Math.round(-1.5)的返回值是-1。四舍五入的原理是在参数上加0.5然后做向下取整。
System.out.println(Math.round(-1.5)); //-1
System.out.println(Math.round(-1.6)); //-2
本文详细介绍了Java中的Math.round()方法,该方法用于四舍五入操作。当传入参数为-1.5时,返回值为-1;传入-1.6则返回-2。文章通过具体示例展示了四舍五入的实现原理,即在数值上加0.5后再向下取整。
Math.round(-1.5)的返回值是-1。四舍五入的原理是在参数上加0.5然后做向下取整。
System.out.println(Math.round(-1.5)); //-1
System.out.println(Math.round(-1.6)); //-2

被折叠的 条评论
为什么被折叠?