floor() in C++

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Overview

The floor in C++ is an inbuilt function that returns an integer value that is less than or equal to the argument. For example, the function floor(3.78) will return the integer value of 3 as an output. The floor in C++ is defined in the <Cmath> header file.

What is floor() in C++

In C++, the floor function returns the largest integer, which is less than or equal to the given argument. The floor in C++ is defined in the cmath header file in C++.

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Example

Output

Explanation

The code discussed above passes a floating value of 2.72.7 to the floor function as an argument. The largest integer which is less than or equal to 2.72.7 is 22. Thus the floor function returns an integer value of 22 as the output.

Syntax of the floor in C++

The syntax of the floor in C++ is as follows:

We need to pass the argument inside the floor()floor() function of which we want the floor value as an output. The argument can be a real number of any data type.

Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science

Parameters of the floor in C++

The floor in C++, defined in the cmath header file, takes a floating-point number whose floor value is to be computed. The parameters can be of the type:

  • double
  • long double
  • float

Note: When an integer value is passed inside the floor function as an argument, it is type cast into a double data type.

Return Value of floor in C++

The floor in C++ returns an integer value that is less than or equal to the argument passed in the floor function.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

floor for Integer Values in C++

When an integer value is passed to the floor in C++ as an argument, the return value is equal to the argument itself.

Example

Output

floor for Double and Float Values in C++

When a floating-point number is passed as an argument, the floor in C++ returns the largest integer that is less than or equal to the argument.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Example

Output

Special Cases for floor in C++

Below are some of the special cases of the floorfloor in C++.

Output

Conclusion

  • The floorfloor is an inbuilt function in C++ that returns an integer value that is less than or equal to the argument.
  • Similar to the floor in C++, the ceil()ceil() function in C++ returns an integer value greater than or equal to the argument.

See also