static double rint(double a)
描述 (Description)
java.lang.StrictMath.rint()方法返回值与参数最接近的double值,并且等于数学整数。 如果两个数学整数的double值同样接近参数的值,则结果是偶数的整数值。它包括这些情况 -
- 如果参数值已经等于数学整数,则结果与参数相同。
- 如果参数为NaN或无穷大或正零或负零,则结果与参数相同。
声明 (Declaration)
以下是java.lang.StrictMath.rint()方法的声明
public static double rint(double a)
参数 (Parameters)
a - 这是要使用的值。
返回值 (Return Value)
此方法将最接近的浮点值返回到等于数学整数的值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.lang.StrictMath.rint()方法的用法。
package com.iowiki;
import java.lang.*;
public class StrictMathDemo {
public static void main(String[] args) {
double d1 = 6.1 , d2 = 57.5 , d3 = 9.7;
/* returns the double value that is close to the argument
and is equal to a mathematical integer. */
double rintValue = StrictMath.rint(d1);
System.out.println("integer value closest to " + d1 + " = " + rintValue);
rintValue = StrictMath.rint(d2);
System.out.println("integer value closest to " + d2 + " = " + rintValue);
rintValue = StrictMath.rint(d3);
System.out.println("integer value closest to " + d3 + " = " + rintValue);
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
integer value closest to 6.1 = 6.0
integer value closest to 57.5 = 58.0
integer value closest to 9.7 = 10.0