ParseFloat function in JavaScript

前端 未结 5 735
暖寄归人
暖寄归人 2021-02-14 04:09

When I am adding two textbox values that are 1.001 and 0.001 and then I do a parseFloat I get 1.0019999999. I wan

5条回答
  •  庸人自扰
    2021-02-14 05:00

    The Javascript Number class has a toFixed() function that will get you what you want.

    So you could do parseFloat("1.0019999").toFixed(3) and that would give you 1.002.

    The parameter (3 in this case) is the number of digits to show after the decimal point

提交回复
热议问题