C++ floor()

StevenSwiniarski's avatar
Published Jul 16, 2021Updated Dec 21, 2022
Contribute to Docs

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours

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);

Codebyte Example

Use floor() to round down the double 12.3456:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn C++ on Codecademy

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
    • Beginner Friendly.
      11 hours