Varada Varada - 2 months ago 14
Javascript Question

convert a javascript string variable to decimal/money

how can we convert a javascript string variable to decimal ?

is there a function such as

parseInt(document.getElementById(amtid4).innerHTML)

Answer

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.