floor()

The floor() function returns the first whole number that is less than or equal to the argument.

Syntax

The cmath library must be added at the top of the file.

std::floor(n);

Argument must be a double/float/long double, and the return value will be the same type.

Example

double result;
result = std::floor(n);

Codecademy Example

Use floor() to round down the double 12.3456:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn C++ on Codecademy

Contributors