= argument
Format
#include <math.h> double floor(double x); float floorf(float x); long double floorl(long double x);float floor(float x);
long double floor(long double x);
Language Level: ANSI, POSIX, XPG4
floor calculates the largest integer that is less than or equal
to x.
Note:
C++ prototypes
float floor(float x); long double floor(long double x);
are disabled when you compile using the lang(compatmath) option.
Return Value
floor returns the floating-point result as a double
value.
The result of floor cannot have a range error.
Example
This example assigns y 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);
return 0;
/******************************************
The output should be:
floor( 2.8 ) = 2.000000
floor( -2.8 ) = -3.000000
******************************************/
}
![]()
ceil -- Find Integer >= Argument
fmod -- Calculate Floating-Point
Remainder
<math.h>
lang(compatmath) option