文章内容
2021/9/29 9:57:35,作 者: 黄兵
JS取整以及四舍五入
- 丢弃小数部分,保留整数部分
parseInt(7/2)
- 向上取整,有小数就整数部分加1
Math.ceil(7/2)
- 四舍五入
Math.round(7/2)
- 向下取整
Math.floor(7/2)
- 保留小数位数
10.989.toFixed(2) // 10.99 10.984.toFixed(2) // 10.98
parseInt(7/2)
Math.ceil(7/2)
Math.round(7/2)
Math.floor(7/2)
10.989.toFixed(2) // 10.99 10.984.toFixed(2) // 10.98
评论列表