ParseFloat function in JavaScript

前端 未结 5 739
暖寄归人
暖寄归人 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 04:46

    The javascript methods Number.toFixed() and Number.toPrecision() can help here, but they return a String. A possible solution is as follows:

    var x = parseFloat(parseFloat("1.0019999999").toPrecision(3));
    

提交回复
热议问题