Math类提供了三个取整方法分别是
- Math.ceil()、Math.floor()、Math.round()
Math.ceil() 方法 :向上取整
- Math.ceil (11.5) = 12
- Math.ceil (11.3) = 12
- Math.ceil (-11.5) = -11
- Math.ceil (-11.3) = -11
Math.floor() 方法 :向下取整
- Math.floor (11.3) = 11
- Math.floor (11.6) = 11
- Math.floor (-11.3)= -12
- Math.floor (-11.6) = -12
Math.round() 方法 :四舍五入
- Math.round (11.6) = 12
- Math.round (11.3) = 11
- Math.round (-11.6) = -11
- Math.round (-11.3) = -11