C++ Math llrint()
C++ Math llrint()
该函数使用当前舍入模式舍入给定值,并返回long long int类型的值。
语法
假设数字为" x"。语法为:
long long int llrint(data_type x);
参数
x : 要取整的值。
返回值
它返回四舍五入后的值" x",并且该值的返回类型为long long int。
示例1
让我们看看舍入方向为向上时的简单示例。
#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
示例2
让我们看一个简单的示例,取整方向向下。
#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