C++ Math nearingint()
C++ Math nearingint()
该函数使用当前的舍入方法将给定值舍入为附近的整数值。 fegetround描述了当前的舍入方法。
语法
假设数字是" x"。语法为:
return_type nearbyint(data_type x);
注意: return_type可以是float,double或long double。
参数
x : 该值可以是float或double。
返回值
使用舍入方法将x的舍入值返回到附近的整数值。
示例1
让我们看一个简单的例子。
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
float x=2.3;
std::cout << "Value of x is:" <<x<< std::endl;
cout<<"Rounding to nearby,value is :"<<nearbyint(x);
return 0;
}
输出:
Value of x is:2.3
Rounding to nearby,value is :2