该函数使用当前的舍入方法将给定值舍入为附近的整数值。 fegetround描述了当前的舍入方法。
假设数字是“ x”。语法为:
return_type nearbyint(data_type x);
x :该值可以是float或double。
它使用舍入方法将x的舍入值返回到附近的整数值。
让我们看一个简单的例子。
#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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)