Is there a way to use the below JavaScript code to use comma's? For example the var num = 1924.00
Is there way to get it to display as 1,924.00?
var num = parseFloat(totalAmount).toFixed(2);
Is there a way to use the below JavaScript code to use comma's? For example the var num = 1924.00
Is there way to get it to display as 1,924.00?
var num = parseFloat(totalAmount).toFixed(2);
You could use a specific regex like this one in the function below:
function format_currency( value ) {
return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
If you want to use it in conjuction with the .toFixed(), just do like this:
format_currency( 1245.3.toFixed(2) );
Hope it helps.