I ran into an issue with the output of calculated sub-total and total fields. I need to calculate the amount based on unit quantity and price per unit in a table and after that I need a total for all the units together. I have that working fine. My issue is that when I put in the price in thousands per unit the subtotal and total fields gives an output in only 2 or 3 digits without showing the zeros. As you can see in the example below it shows the total to be 30 instead of 30,000 and 5 instead of 5,000 and 35 instead of 35,000. How can I format that?
Here is Java Script that I have right now:
$(document).ready(function () {
$('.cf-table-block').on('blur', 'input', sumtotal);
function sumtotal() {
var sum = 0;
$('.cf-table-block tbody tr').each(function () {
var s = 0;
s = parseNumber($(this).find('.price input').val()) * parseNumber($(this).find('.quantity input').val());
$(this).find('.subtotal input').val(s);
sum += s;
});
sum += parseNumber($('.tax input').val()) + parseNumber($('.shipping input').val());
$('.total input').val(sum);
}
function parseNumber(n) {
var f = parseFloat(n); //Convert to float number.
return isNaN(f) ? 0 : f; //treat invalid input as 0;
}
});
Thank you!