C Standard Library

C <math.h> - floor() Function



The C <math.h> 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 floorf (float x);
long double floorl (long double 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 <stdio.h>
#include <math.h>
 
int main (){
  printf("%lf\n", floor(10.5));
  printf("%lf\n", floor(-10.5));
  printf("%lf\n", floor(0.5));
  printf("%lf\n", floor(-0.5));   
  return 0;
}

The output of the above code will be:

10.000000
-11.000000
0.000000
-1.000000

❮ C <math.h> Library