Javascript multiplying incorrectly, causing incorrect rounding

后端 未结 3 1909
名媛妹妹
名媛妹妹 2021-01-02 23:54

When I pull the values I want to multiply, they\'re strings. So I pull them, parse them as floats (to preserve the decimal places), and multiply them together.



        
3条回答
  •  感情败类
    2021-01-03 00:11

    JavaScript/TypeScript have only one Number class which is not that good. I have the same problem as I am using TypeScript. I solved my problem by using decimal.js-light library.

    new Decimal(78).mul(7).mul(0.0725) returns as expected 39.585
    

提交回复
热议问题