English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
double floor(double x) returns the largest integer less than or equal to x.
double floor(double arg)
The floor() function takes a single parameter and returns a value of type double.
It is<math.h>Defined in the header file.
For example:
If you put2.3Passed to floor(), it will return2.
To calculate the floor() of long double or float, you can use the following prototype.
long double floorl(long double arg); float floorf(float arg);
#include <stdio.h> #include <math.h> int main() { float val1, val2, val3, val4; val1 = 9.6; val2 = 9.2; val3 = -5.8; val4 = -5.3; printf("Floor1 = %.1lf\n", floor(val1)); printf("Floor2 = %.1lf\n", floor(val2)); //Note Negative Numbers printf("Floor3 = %.1lf\n", floor(val3)); printf("Floor4 = %.1lf\n", floor(val4)); return(0); }
Output Result
Floor1 = 9.0 Floor2 = 9.0 Floor3 = -6.0 Floor4 = -6.0