方法rint返回值最接近參數(shù)的整數(shù)。
double rint(double d)
d - 它接受一個double值作為參數(shù)。
此方法返回值最接近參數(shù)的整數(shù)。 返回為雙精度。
下面是一個使用這個方法的例子 -
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
更多建議: