broken toFixed implementation

后端 未结 6 2200
陌清茗
陌清茗 2020-11-27 21:51

The default implementation of javascript\'s \"Number.toFixed\" appears to be a bit broken.

console.log((8.555).toFixed(2));    // returns 8.56
console.log((         


        
6条回答
  •  自闭症患者
    2020-11-27 22:32

    It's probably related to floating point problems, see How to deal with floating point number precision in JavaScript?

提交回复
热议问题