rint函数 java
C ++ rint()函数 (C++ rint() function)
rint() function is a library function of cmath header. It is used to round the given value to an integral value based on the specified direction by fegetround() function. It accepts a parameter and returns the rounded value.
rint()函数是cmath标头的库函数。 它用于通过fegetround()函数根据指定的方向将给定值舍入为整数值。 它接受一个参数并返回四舍五入的值。
Syntax of rint() function:
rint()函数的语法:
C++11:
C ++ 11:
double rint (double x);
float rint (float x);
long double rint (long double x);
double rint (T x);
Parameter(s):
参数:
x – represents the value to round.
x –表示要取整的值。
Return value:
返回值:
It returns rounded (to an integral value) value.
它返回四舍五入(至整数值)的值。
Example:
例:
Input:
double x = 123.4;
Function call:
rint(x);
Output:
123
Input:
double x = 123.5;
Function call:
rint(x);
Output:
124
C ++代码演示rint()函数的示例 (C++ code to demonstrate the example of rint() function)
// C++ code to demonstrate the example of
// rint() function
#include <iostream>
#include <cmath>
#include <fenv.h> // for fegetround()
using namespace std;
int main()
{
double x = 0.0;
cout << "Specified rounding is: ";
switch (fegetround()) {
case FE_DOWNWARD:
cout << "Downward" << endl;
break;
case FE_TONEAREST:
cout << "To-nearest" << endl;
break;
case FE_TOWARDZERO:
cout << "Toward-zero" << endl;
break;
case FE_UPWARD:
cout << "Upward" << endl;
break;
default:
cout << "Unknown" << endl;
}
x = 123.4;
cout << "rint(" << x << "): " << rint(x) << endl;
x = 123.5;
cout << "rint(" << x << "): " << rint(x) << endl;
x = 123.6;
cout << "rint(" << x << "): " << rint(x) << endl;
x = -123.4;
cout << "rint(" << x << "): " << rint(x) << endl;
x = -123.5;
cout << "rint(" << x << "): " << rint(x) << endl;
x = -123.6;
cout << "rint(" << x << "): " << rint(x) << endl;
return 0;
}
Output
输出量
Specified rounding is: To-nearest
rint(123.4): 123
rint(123.5): 124
rint(123.6): 124
rint(-123.4): -123
rint(-123.5): -124
rint(-123.6): -124
Reference: C++ rint() function
参考: C ++ rint()函数
翻译自: https://www.includehelp.com/cpp-tutorial/rint-function-with-example.aspx
rint函数 java