English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
double floor(double x); float floor(float x); long double floor(long double x); double floor(T x); //for integer
The floor() function takes a single parameter and returns a value of type double, float, or long double. This function starts with<cmath>defined in the header file.
The floor() function takes one parameter, whose base value is calculated.
The floor() function returns the maximum possible integer value less than or equal to the given parameter.
#include <iostream> #include <cmath> using namespace std; int main() { double x = 10.25, result; result = floor(x); cout << "Floor of " << x << " = " << result << endl; x = -34.251; result = floor(x); cout << "Floor of " << x << " = " << result << endl; x = 0.71; result = floor(x); cout << "Floor of " << x << " = " << result << endl; return 0; }
When running the program, the output is:
Floor of 10.25 = 10 Floor of -34.251 = -35 Floor of 0.71 = 0
#include <iostream> #include <cmath> using namespace std; int main() { int x = 15; double result; result = floor(x); cout << "Floor of " << x << " = " << result << endl; return 0; }
When running the program, the output is:
Floor of 15 = 15
The lower bound of an integer value is the integer value itself, so the lower bound function is not used for integer values in practice.