bit floating point math error in JavaScript

This question already has an answer here:

  • Is floating point math broken? 23 answers

  • The "solution" to the (non-)error is to ignore it, and ensure that you use an appropriate function, ie toFixed(n) , to present the number with the desired number of decimal places.

    It's important to know the difference between the internal representation of a value, and how to present that value to the end user.


    您可以使用https://github.com/ekg/fraction.js库获取中间值,并将最终结果转换回十进制值以最大限度地减少错误。

    链接地址: http://www.djcxy.com/p/27504.html

    上一篇: (.1f + .2f ==。3f)!=(.1f + .2f).Equals(.3f)为什么?

    下一篇: 在JavaScript中的位浮点数学错误