JS Math对象

四舍五入

Math.round(x)

1、负数四舍五入的原则 

Math.round(-4.4) //-4
Math.round(-4.6) //-5
//当距离两个整数一样时,取大整数
Math.round(4.5) //5
Math.round(-4.5) //-4 

2、如果保留3位小数,然后四舍五入 

Math.round(x*1000)/1000

posted on 2018-01-08 17:30  dreamstar  阅读(39)  评论(0编辑  收藏  举报