C library functions - floor ()
description
C library functiondouble floor (double x) Returns the largest integer value less than or equal to x.
statement
Here is the () function declaration floor.
double floor(double x)
parameter
- x - floating-point value.
return value
This function returns the largest integer value not greater than x.
Examples
The following example demonstrates the floor () function is used.
#include <stdio.h> #include <math.h> int main () { float val1, val2, val3, val4; val1 = 1.6; val2 = 1.2; val3 = 2.8; val4 = 2.3; printf("Value1 = %.1lf\n", floor(val1)); printf("Value2 = %.1lf\n", floor(val2)); printf("Value3 = %.1lf\n", floor(val3)); printf("Value4 = %.1lf\n", floor(val4)); return(0); }
Let's compile and run the above program, which will result in the following:
Value1 = 1.0 Value2 = 1.0 Value3 = 2.0 Value4 = 2.0