JS toFixed 精度问题

暗恋桃埖源 / 2024-07-16 / 原文

1.555.toFixed(2)
// '1.55'
2.555.toFixed(2)
// '2.56'

可以看出,1.555 保留两位小数,没有四舍五入, 而 2.555 保留两位小数,进行了四舍五入。