数学方法总结
Math.ceil 向上取整(大于或等于给定数字的最小整数。)
1 | console.log(Math.ceil(0.333)) // 1 |
Math.floor 向下取整(一个表示小于或等于指定数字的最大整数的数字。)
1 | console.log(Math.floor(0.333)) // 0 |
Math.round 四舍五入 给定数字值四舍五入到最接近的整数。
1 | console.log(Math.round(45.333)) // 45 |
toFixed 保留小数点后的几位(传几就保留到几位)
1 | let number = 0.9999999999 |