编辑这个页面须要登录或更高权限!
double floor(double x); float floor(float x); long double floor(long double x); double floor(T x); //为整型
floor()函数采用单个参数,并返回double,float或long double类型的值。此函数在<cmath>头文件中定义。
floor()函数采用一个参数,该参数的底值被计算。
floor()函数返回的最大可能整数值小于或等于给定参数。
#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; }
运行该程序时,输出为:
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; }
运行该程序时,输出为:
Floor of 15 = 15
整数值的下限就是整数值本身,所以实际中对整数值不使用下限函数。