convert a JavaScript string variable to decimal/money

后端 未结 7 1309
盖世英雄少女心
盖世英雄少女心 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:20

    You can also use the Number constructor/function (no need for a radix and usable for both integers and floats):

    Number('09'); /=> 9
    Number('09.0987'); /=> 9.0987
    

    Alternatively like Andy E said in the comments you can use + for conversion

    +'09'; /=> 9
    +'09.0987'; /=> 9.0987
    

提交回复
热议问题