floor 取值在左边;(向下取整)
ceil 取值在右边;(向上取整)
round 返回最接近它的整数,若有两个返回接近的整数,则取最大的那个
当前值+0.5,然后左边取值;(向下取整)
// Math.round 返回最接近它的整数,若有两个返回接近的整数,则取最大的那个 System.out.println(Math.round(-1.3)); // -1 System.out.println(Math.round(-1.4)); // -1 System.out.println(Math.round(-1.5)); // -1 System.out.println(Math.round(-1.6)); // -2 System.out.println(Math.round(-1.7)); // -2 System.out.println(Math.round(-1.8)); // -2 System.out.println("--------------------------"); System.out.println(Math.round(1.3)); // 1 System.out.println(Math.round(1.4)); // 1 System.out.println(Math.round(1.5)); // 2 System.out.println(Math.round(1.6)); // 2 System.out.println(Math.round(1.7)); // 2 System.out.println(Math.round(1.8)); // 2 System.out.println("--------------------------"); // 取值在右边;(向上取整) System.out.println(Math.ceil(-1.8)); // -1.0 // 取值在左边;(向下取整) System.out.println(Math.floor(-1.8)); // -2.0