您的位置:首页 > 编程语言 > Java开发

Math中的round、ceil、floor的功能。

2017-05-22 21:37 447 查看
round,意思就是周围,所以可以理解为四舍五入

ceil,天花板,所以理解为向上取整,

floor,地板,所以理解为向下取整

举个例子

public class MathTrap {

public static void main(String[] args) {
System.out.println(Math.round(0.5));
System.out.println(Math.ceil(0.5));
System.out.println(Math.floor(0.5));
}

}结果为:



总结一下:

round就是加上0.5在向下取整

ceil就是像是向上取整,即使你讲0.5改成0.4输出的还是1.0

floor就是向下取整,所以0.5向下取整的结果为0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java Math round ceil floor