- public class MathDemo
- {
- public static void println(Object obj)
- {
- System.out.println(obj);
- }
- public static void main(String []agrs)
- {
- /*println(Math.ceil(16.3));//17.0
- println(Math.ceil(-16.3));//-16.0
- println(Math.floor(16.3));//16.0
- println(Math.floor(-16.3));//-17.0*/
- //floor地板 向下去整
- //ceil天花板 向上取整
- println("====================");
- println(Math.round(16.3));//16
- println(Math.round(-16.3));//-16
- println(Math.round(-16.5));//-16
- println(Math.round(16.5));//17
- // (long)Math.floor(a + 0.5d)
- println("====================");
- double value = 4.015;
- println(value * 100);//401.49999999999994
- println(Math.round(value*100));//401
- value = Math.round(value*100)/100.0;
- println(value);//4.01
- }
- }
复制代码 |
|