Java rint() 方法
rint() 方法返回最接近參數(shù)的整數(shù)值。
語法
該方法有以下幾種語法格式:
double rint(double d)
參數(shù)
- double 原始數(shù)據(jù)類型。
返回值
返回 double 類型數(shù)組,是最接近參數(shù)的整數(shù)值。
實例
public class Test{ public 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
更多建議: