- Math.round(11.5),Math.round(-11.5)
将括号内的数+0.5之后,向下取值.round(3.4)就是3.4+0.5=3.9,向下取值是3,所以round(3.4)=3;
round(-10.5)就是-10.5+0.5=-10,向下取值就是-10,所以round(-10.5)=-10
==> Math.round(11.5)=12 Math.round(-11.5) = 11
- Math.ceil求最小的整数,但不小于本身[ceil的英文意义是天花板,该方法就表示向上取整
]
==>Math.ceil(11.3)的结果为12,Math.ceil(-11.3)的结果是-11
- Math.floor求最大的整数,但不大于本身. [floor的英文意义是地板,该方法就表示向下取整,
]
==> Math.floor(11.6)的结果为11,Math.floor(-11.6)的结果是-12
练习快速写出
System.out.println(Math.round(-1.1)); //-1
System.out.println(Math.round(-1.9)); // -2
System.out.println(Math.round(1.1)); //1
System.out.println(Math.round(1.9)); // 2