67

为什么(2.55).toFixed(1)等于2.5?

 6 years ago
source link: https://juejin.im/post/5a11a9fef265da43284073b4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
上次遇到了一个奇怪的问题:JS的(2.55).toFixed(1)输出是2.5,而不是四舍五入的2.6,这是为什么呢?进一步观察:发现,并不是所有的都不正常,1.55的四舍五入还是对的,为什么2.55、3.45就不对呢?这个需要我们在源码里面找答案。数字在V8

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK