|
1963| 3
|
[有事请教] 遇到了取整bug,哪位大佬懂? |
|
悬赏100星屑已解决
最佳答案let x=1.00000001;
let xy=2.0000000000000003;
console.log(x)
console.log(xy)
console.log(Math.floor(x))
console.log(Math.ceil(xy))
可以啊不过16位就是最大值了 你可以看到Math.ceil 2.0000000000000003 变成2.0000000000000004 再多一位就变成2
如果你知道想要保留小数的多少位就用toFixed
xy.toFixed(5) 2.20000 保留5位小数
保留完再用 round fioor ceil 就可以了
console.log(Math.ceil(xy.toFixed(2)))
...
| ||