JavaScript 取整的几种方法
文章目录
-
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
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论