-
Math.floor() 向下取整
Math.floor(3.141592654) // 3
-
Math.ceil() 向上取整
Math.ceil(3.141592654) // 4
-
Math.round() 四舍五入
Math.round(3.141592654) // 3
-
parseInt() 去掉小数点和小数点后的部分
parseInt(3.141592654) // 3
-
~~ 将数据转化为Number类型
~~3.141592654 // 3
JavaScript 取整的几种方法
9 min read