JAVA中的Math.round()方法的原理是:
将参数加0.5,然后向下取整。
如:
Math.round(1.5);1.5+0.5 = 2.0,向下取整为2.0;
Math.round(-1.5); -1.5+0.5 = -1.0,向下取整为-1.0;
Math.round(-1.6); -1.6+0.5=-1.1,向下取整为-2.0;
Math.round(-1.4);-1.4+0.5=-0.9,向下取整为-1.0。
JAVA中的Math.round()方法的原理是:
将参数加0.5,然后向下取整。
如:
Math.round(1.5);1.5+0.5 = 2.0,向下取整为2.0;
Math.round(-1.5); -1.5+0.5 = -1.0,向下取整为-1.0;
Math.round(-1.6); -1.6+0.5=-1.1,向下取整为-2.0;
Math.round(-1.4);-1.4+0.5=-0.9,向下取整为-1.0。