Java 中 Math.rint 与 Math.round 的用法

rint(x):x取整为它最接近的整数,如果x与两个整数的距离相等,则返回其中为偶数的那一个。

round(x):返回Math.floor(x+0.5),即“四舍五入”值。

例:

rint(3.5) = 4

rint(4.5) = 4

round(4.5) = 4

round(4.4) = 4 

猜你喜欢

转载自blog.csdn.net/Tyrannosar/article/details/81060090