结论:Math.round()的取整规则不完全符合四舍六入五成双,而是符合加0.5,再进行向下取整Math.floor()。
// Math.round(),规则:四舍六入五成双(非真正的五成双)
//四舍六入,即若出现负数,先转为整数,在四舍六入,最后加上负号
System.out.println(Math.round(3.4)); //3
System.out.println(Math.floor(3.4+0.5));
System.out.println(Math.round(3.6)); //4
System.out.println(Math.floor(3.6+0.5));
System.out.println(Math.round(-3.4)); //-3
System.out.println(Math.floor(-3.4+0.5));
System.out.println(Math.round(-3.6)); //-4
System.out.println(Math.floor(-3.6+0.5));
//五成双,即当出现0.5结尾的时候,就再加上0.5,5就成双了
System.out.println(Math.round(3.5)); //4=3.5+0.5
System.out.println(Math.floor(3.5+0.5));
System.out.println(Math.round(-3.5)); //-3=-3.5+0.5
System.out.println(Math.floor(-3.5+0.5));
//结论:Math.round()的取整规则不完全符合四舍六入五成双,而是符合加0.5,再进行向下取整Math.floor()
//也即:返回最接近它的整数,若有两个相同接近的整数,则取最大的那个
}`
结论参考文章:https://blog.csdn.net/shruber/article/details/78413706