Math对象相关

Math.random()    返回大于等于0,小于1之间的数 [0,1)    //0.3050501310540108 

Math.floor(2.6)    向下取整  //2

Math.ceil(2.6)     向上取整  //3

Math.round()      四舍五入取整

Math.round()参数是正数,正常四舍五入

Math.round(2.6)   //3

Math.round(2.4)   //2

Math.round(2.5)   //2.6

Math.round()参数是负数,并且小数部分恰好等于0.5的情况需要注意,需要多看0.5后边一位

Math.round(-2.5)     //-2

Math.round(-2.51)   //-3

Math.round(-2.4)    //-2

原文地址:https://www.cnblogs.com/qq254980080/p/12159545.html