I would like the sum calculated from the script below to display two decimals, and thousands separated by a comma. At this stage it only display the two decimals. I am new to programming and have tried various techniques but could not solve the problem. Below my JS code so far:
function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".txt").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
$("#sum").html(sum.toFixed(2).replace(',', ''));
}