它将值舍入到不大于给定值的最接近的整数。
例如:
floor(8.2)=8.0; floor(-8.8)=-9.0;
floor - 语法
假设数字是“ x”。语法为:
double floor(double x);
floor - 参数
x : 四舍五入到最接近的整数的值。
floor - 返回值
它返回舍入到不大于x的最接近整数的值。
floor - 例子1
让我们看一个简单的例子,考虑正值。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=7.8;
std::cout << "Initial value of x is : " << x<<std::endl;
cout<<"Now, the value of x is :"<<floor(x);
return 0;
}
输出:
Initial value of x is : 7.8 Now, the value of x is :7
floor - 例子2
让我们看一个简单的例子,考虑负值。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=-10.2;
std::cout << "Initial value of x is : " << x<<std::endl;
cout<<"Now, the value of x is :"<<floor(x);
return 0;
}
输出:
Initial value of x is : -10.2 Now, the value of x is :-11