**
java中Math的取整方法
**
- Math.ceil方法:表示向上取整。
例:
System.out.println(Math.ceil(1.01));
System.out.println(Math.ceil(-1.01));
System.out.println(Math.ceil(1.5));
System.out.println(Math.ceil(-1.5));
运行结果:
2.0
-1.0
2.0
-1.0 - Math.floor方法:表示向下取整。
例:
System.out.println(Math.floor(1.01));
System.out.println(Math.floor(-1.01));
System.out.println(Math.floor(1.5));
System.out.println(Math.floor(-1.5));
运行结果:
1.0
-2.0
1.0
-2.0 - Math.round方法:表示四舍五入运行。
例:
System.out.println(Math.round(1.01));
System.out.println(Math.round(-1.01));
System.out.println(Math.round(1.5));
System.out.println(Math.round(-1.5));
运行结果:
1
-1
2
-1