How to parse float with two decimal places in javascript?

前端 未结 16 1742
春和景丽
春和景丽 2020-11-27 08:55

I have the following code. I would like to have it such that if price_result equals an integer, let\'s say 10, then I would like to add two decimal places. So 10 would be 10

16条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-27 09:50

    You can use .toFixed() to for float value 2 digits

    Exampale

    let newValue = parseFloat(9.990000).toFixed(2)
    
    //output
    9.99
    

提交回复
热议问题