Math类中的三大取整函数:
1.ceil(返回double类型)
2.floor(返回double类型)
3.round(返回int类型)
1.ceil:意思是天花板,java中叫做向上取整,大于等于该数字的最接近的整数
例:
Math.ceil(10.2)=11.0
Math.ceil(-10.2)=-10.0
Math.ceil(10.7)=11.0
Math.ceil(-10.2)=-10.0
2.floor:意思是地板,java中叫做向下取整,小于等于该数字的最接近的整数
例:
Math.floor(-10.2)=-11.0
Math.floor(10.7)=10.0
Math.floor(-10.2)=-11.0
3.round:就是四舍五入
例:
Math.round(10.2)=10
Math.round(-10.2)=-10
Math.round(10.5)=11
Math.round(-10.5)=-10
Math.round(-10.7)=-11
本文详细介绍了Java中Math类的三种取整函数:ceil、floor 和 round 的使用方法及示例。ceil 函数用于向上取整,floor 函数用于向下取整,而 round 函数则实现了四舍五入。
626

被折叠的 条评论
为什么被折叠?



