java小数取整

java中提供三种小数取整方式

  1. Math.ceil()  
  2. Math.floor()
  3. 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

posted @ 2016-12-27 22:16  彩蛋飞  阅读(3326)  评论(0)    收藏  举报