C++ Math floor()
C++ Math floor()
它将数值四舍五入为最接近的整数,该整数不大于给定值。
例如:
floor(8.2)=8.0;
floor(-8.8)=-9.0;
语法
假设数字为" x"。语法为:
参数
x : 它是四舍五入到最接近整数的值。
返回value
它返回四舍五入到不大于x的最接近整数的值。
示例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
示例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