Groovy - rint()



rint 方法返回與引數值最接近的整數。

語法

double rint(double d)

引數

d - 它接受一個雙精度值作為引數。

返回值

此方法返回與引數值最接近的整數。作為雙精度數返回。

示例

以下是一個對該方法的使用示例 −

class Example { 
   static void main(String[] args){ 
      double d = 100.675; 
      double e = 100.500; 
      double f = 100.200;
		
      System.out.println(Math.rint(d)); 
      System.out.println(Math.rint(e)); 
      System.out.println(Math.rint(f)); 
   } 
}

當我們執行以上程式時,將得到以下結果 −

101.0 
100.0 
100.0
groovy_numbers.htm
廣告
© . All rights reserved.