一、区分Math.ceil() 、Math.floor() 、Math.round():
private final static double target = 2.1;
public static void main(String[] args)
{
double ceil = Math.ceil(target);
double floor = Math.floor(target);
double round = Math.round(target);
System.out.print("ceil = " + ceil + ", floor = " + floor + ", round = " + round);
}
输出结果为:ceil = 3.0, floor = 2.0, round = 2.0
结论:
**1. Math.ceil():向上取整(取大于目标值的最小整数)。
2. Math.floor():向下取整(取小于目标值的最大整数)。
3. Math.round(): 与数学上的四舍五入取整相同。**