java小数取整
java中提供三种小数取整方式
- Math.ceil()
- Math.floor()
- Math.round()
ceil:天花板,向上quzheng
Math.ceil(11.5) = 12
Math.ceil(-11.5) = -11
floor:地,向下取整
Math.floor(11.5) = 11
Math.floor(-11.5) = -12
round:4舍5入
Math.round(x + 0.5),再向下取整
当 x = 11.5 时,Math.round(x + 0.5) = Math.round(12) = 12
当 x = -11.5时,Math.round(x + 0.5) = Math.round(-11) = -11

浙公网安备 33010602011771号