C++ Standard Library C++ STL Library

C++ <cmath> - floor() Function



The C++ <cmath> floor() function returns the next lowest integer value by rounding down the specified number, if necessary. In other words, it rounds the fraction DOWN of the given number.

Syntax

double floor (double x);
float floor (float x);
long double floor (long double x);
double floor (double x);
float floor (float x);
long double floor (long double x);
//additional overloads for integral types  
double floor (T x);                             

Parameters

x Specify a number.

Return Value

Returns the next lowest integer value by rounding DOWN the specified number, if necessary.

Example:

In the example below, floor() function is used to round the fraction DOWN of the specified number.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){
  cout<<floor(10.5)<<"\n";
  cout<<floor(-10.5)<<"\n";
  cout<<floor(0.5)<<"\n";
  cout<<floor(-0.5)<<"\n";   
  return 0;
}

The output of the above code will be:

10
-11
0
-1

❮ C++ <cmath> Library