该函数使用当前舍入模式舍入给定值,并返回long long int类型的值。
假设数字是“ x”。语法为:
long long int llrint(data_type x);
x :要四舍五入的值。
它返回舍入后的值" x",并且该值的返回类型为long long int。
让我们看一个简单的例子,当舍入方向为向上时。
#include <iostream> #include<math.h> #include<cfenv> using namespace std; int main() { float x=5.3; std::cout << "Value of x is :" << x<<std::endl; fesetround(FE_UPWARD); cout<<"Rounded value of x is :"<<llrint(x); return 0; }
输出:
Value of x is :5.3 Rounded value of x is :6
让我们看一个简单的例子,当舍入方向向下时。
#include <iostream> #include<math.h> #include<cfenv> using namespace std; int main() { double x=7.9; std::cout << "Value of x is :" << x<<std::endl; fesetround(FE_DOWNWARD); cout<<"Rounded value of x is :"<<llrint(x); return 0; }
输出:
Value of x is :7.9 Rounded value of x is :7
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)