double floor(double x); float floor(float x); long double floor(long double x); double floor(T x); //為整型
floor()函數(shù)采用單個(gè)參數(shù),并返回double,float或long double類型的值。此函數(shù)在<cmath>頭文件中定義。
floor()函數(shù)采用一個(gè)參數(shù),該參數(shù)的底值被計(jì)算。
floor()函數(shù)返回的最大可能整數(shù)值小于或等于給定參數(shù)。
#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;
}運(yùn)行該程序時(shí),輸出為:
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;
}運(yùn)行該程序時(shí),輸出為:
Floor of 15 = 15
整數(shù)值的下限就是整數(shù)值本身,所以實(shí)際中對(duì)整數(shù)值不使用下限函數(shù)。