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

posted @ 2020-01-07 08:51  254980080  阅读(157)  评论(0编辑  收藏  举报