C++ Math nearbyint()函数
该函数根据当前的舍入方法将给定的值四舍五入到最接近的整数值。当前的舍入方法由fegetround所描述。
语法
假设一个数为’x’。语法如下:
return_type nearbyint(data_type x);
注意:返回类型可以是float、double或long double。
参数
x :值可以是float或double。
返回值
使用四舍五入方法将x的值返回到最近的整数值。
示例1
让我们看一个简单的示例。
#include
#include
#include
using namespace std;
int main()
{
float x=2.3;
std::cout << "Value of x is:" <
输出:
Value of x is:2.3
Rounding to nearby,value is :2