C floor()

C floor() Prototype

double floor(double arg)

The floor() function takes a single argument and returns adouble type value.

It is defined in <math.h> header file.


For Example:

If 2.3 is passed to floor(), it will return 2.

The function prototypes for the long double and float versions of the floor() function are:

long double floorl(long double arg);
float floorf(float arg);

Example: C floor() Function

#include <stdio.h>
#include <math.h>

int main() {

   double num = -8.33;

   double result = floor(num);

   printf("Floor integer of %.2f = %.0f", num, result);
   return 0;
}

Output

Floor integer of -8.33 = -9
Did you find this article helpful?