public class Test {
public static void main(String[] args) {
long a = Math.round(11.5);
long b = Math.round(-11.5);
System.out.println(a);
System.out.println(b);
}
}
输出
12
-11
Math.round(11.5)的返回值是12,Math.round(-11.5)的返回值是-11。四舍五入的原理是在参数上加0.5然后进行下取整。