目录

static double rint(double a)

描述 (Description)

java.lang.Math.rint(double a)返回值与参数最接近的double值,它等于数学整数。 如果两个数学整数的double值同样接近,则结果是偶数的整数值。 特殊情况 -

  • 如果参数值已经等于数学整数,则结果与参数相同。

  • 如果参数为NaN或无穷大或正零或负零,则结果与参数相同。

声明 (Declaration)

以下是java.lang.Math.rint()方法的声明

public static double rint(double a)

参数 (Parameters)

a - 双倍值。

返回值 (Return Value)

此方法将最接近的浮点值返回到等于数学整数的值。

异常 (Exception)

NA

例子 (Example)

以下示例显示了lang.Math.rint()方法的用法。

package com.iowiki;
import java.lang.*;
public class MathDemo {
   public static void main(String[] args) {
      // get two double numbers
      double x = 1654.9874;
      double y = -9765.134;
      // find the closest integers for these double numbers
      System.out.println("Math.rint(" + x + ")=" + Math.rint(x));
      System.out.println("Math.rint(" + y + ")=" + Math.rint(y));
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Math.rint(1654.9874)=1655.0
Math.rint(-9765.134)=-9765.0
↑回到顶部↑
WIKI教程 @2018