Floor returns the largest integer not greater than
Found is a 4-house 5-in calculation, in which is to be larger than its integer
Ceil is not less than his smallest integer
See examples
  |
math.flo or |
math.round |
math.ceil |
1 |
1 |
1.5 | TD style= "BORDER:0;PADDING:0;" >1
2 |
1.6 |
2 |
2 |
-2 |
-1 |
-1 |
-2 |
-1 |
-1 |
-2 |
-2 |
-1 |
The test procedure is as follows:
public class MyTest {
public static void main(String[] args) {
double[] nums = { 1.4, 1.5, 1.6, -1.4, -1.5, -1.6 };
for (double num : nums) {
test(num);
}
}
private static void test(double num) {
System.out.println("Math.floor(" + num + ")=" + Math.floor(num));
System.out.println("Math.round(" + num + ")=" + Math.round(num));
System.out.println("Math.ceil(" + num + ")=" + Math.ceil(num));
}
}
Run results
Math.floor(1.4)=1.0
Math.round(1.4)=1
Math.ceil(1.4)=2.0
Math.floor(1.5)=1.0
Math.round(1.5)=2
Math.ceil(1.5)=2.0
Math.floor(1.6)=1.0
Math.round(1.6)=2
Math.ceil(1.6)=2.0
Math.floor(-1.4)=-2.0
Math.round(-1.4)=-1
Math.ceil(-1.4)=-1.0
Math.floor(-1.5)=-2.0
Math.round(-1.5)=-1
Math.ceil(-1.5)=-1.0
Math.floor(-1.6)=-2.0
Math.round(-1.6)=-2
Math.ceil(-1.6)=-1.0