JS取整的四种方法

  parseInt() 该方法取整是把小数点后面小数去掉,只保留整数部分。如果要取整的数为正时,类似Math.floor();为负时,类似Math.ceil()

  Math.round() 四舍五入取整

  Math.floor() 向下取整  如Math.floor(1.8) 返回 1;Math.floor(-1.8) 返回 -2;

  Math.ceil()向上取整  如Math.ceil(1.8)返回 2;Math.ceil(-1.8) 返回 -1;

猜你喜欢

转载自blog.51cto.com/13550695/2460661