convert a JavaScript string variable to decimal/money

后端 未结 7 1293
盖世英雄少女心
盖世英雄少女心 2020-12-07 14:05

How can we convert a JavaScript string variable to decimal?

Is there a function such as:

parseInt(document.getElementById(amtid4).innerHTML)
         


        
7条回答
  •  鱼传尺愫
    2020-12-07 14:14

    Yes -- parseFloat.

    parseFloat(document.getElementById(amtid4).innerHTML);
    

    For formatting numbers, use toFixed:

    var num = parseFloat(document.getElementById(amtid4).innerHTML).toFixed(2);
    

    num is now a string with the number formatted with two decimal places.

提交回复
热议问题