美文网首页
JAVA四舍五入取整

JAVA四舍五入取整

作者: WotYang | 来源:发表于2018-11-14 11:06 被阅读0次

Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数;
Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数;
Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数。

Math.ceil(25.9) //26

Math.ceil(25.5) //26

Math.ceil(25.1) //26

Math.ceil(25.0)//25

Math.round(25.9) //26

Math.round(25.5) //26

Math.round(25.1) //25

Math.floor(25.9) //25

Math.floor(25.5) //25

Math.floor(25.1) //25

相关文章

网友评论

      本文标题:JAVA四舍五入取整

      本文链接:https://www.haomeiwen.com/subject/yamdfqtx.html