首页 > 编程语言 > 详细

java小数取整

时间:2016-12-28 01:26:57      阅读:442      评论:0      收藏:0      [点我收藏+]

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

java小数取整

原文:http://www.cnblogs.com/caidanhui/p/6227718.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!