📅  最后修改于: 2020-09-25 07:46:59             🧑  作者: Mango
C++中的llround() 函数对最接近参数的整数值进行四舍五入,一半的情况舍入为零。返回的值是long long int类型。它类似于lround() 函数,但是返回long long int,而lround返回long int。
long long int llround(double x);
long long int llround(float x);
long long int llround(long double x);
long long int llround(T x); // For integral type
llround()函数采用单个参数,并返回long long int类型的值。此函数在
llround() 函数采用单个参数值进行舍入。
llround()函数返回最接近x的整数值,中途情况从零舍入。返回的值是long long int类型。
#include
#include
using namespace std;
int main()
{
long long int result;
double x = 11.16;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
x = 13.87;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
x = 50.5;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
x = -11.16;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
x = -13.87;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
x = -50.5;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
return 0;
}
运行该程序时,输出为:
llround(11.16) = 11
llround(13.87) = 14
llround(50.5) = 51
llround(-11.16) = -11
llround(-13.87) = -14
llround(-50.5) = -51
#include
#include
using namespace std;
int main()
{
int x = 15;
long long int result;
result = llround(x);
cout << "llround(" << x << ") = " << result << endl;
return 0;
}
运行该程序时,输出为:
llround(15) = 15
对于整数值,应用llround 函数将返回与输入相同的值。因此,在实践中,它通常不用于积分值。