📅  最后修改于: 2020-09-25 07:37:36             🧑  作者: Mango
C++中的floor() 函数返回最大可能的整数值,该值小于或等于给定的参数。
double floor(double x);
float floor(float x);
long double floor(long double x);
double floor(T x); // For integral type
floor() 函数采用单个参数,并返回double,float或long double类型的值。此函数在
floor() 函数采用一个参数,该参数的下限值已计算出来。
floor() 函数返回小于或等于给定参数的最大可能整数值。
#include
#include
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
#include
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
整数值的下限是整数值本身,因此在实际中不对下限值使用下限函数 。