Format
#include <math.h>
double floor(double x);
Language Level: ANSI
Threadsafe: Yes.
Description
The floor() function calculates the largest integer that is less than or equal to x.
Return Value
The floor() function returns the floating-point result as a double value.
The result of floor() cannot have a range error.
Example that uses floor()
This example assigns y the value of the largest integer less than or equal to 2.8 and z the value of the largest integer less than or equal to -2.8.
#include <math.h>
#include <stdio.h>
int main(void)
{
double y, z;
y = floor(2.8);
z = floor(-2.8);
printf("floor( 2.8 ) = %lf\n", y);
printf("floor( -2.8 ) = %lf\n", z);
}
/******************* Output should be similar to: ***************
floor( 2.8 ) = 2.000000
floor( -2.8 ) = -3.000000
*/
Related Information