My javascript loops through a set of tags and take in their innerText which contains floating numbers.
var total_amount = 0.00;
function update_totals() {
total_amount = 0;
tableRows = document.querySelectorAll('[id^="amount_"]');
for (var i = 0, len = tableRows.length; i < len; i++) {
total_amount = total_amount + parseFloat(tableRows[i].innerText).toFixed(2);
}
tax = parseFloat(total_amount * 5/100).toFixed(2);
gross_amount = parseFloat(total_amount + tax);
console.log(total_amount);
console.log(tax);
console.log(gross_amount);
}
My elements innerText is 3800.00 and 2599.99 But the console.log shows
03800.002599.99
Nan
3800.002599
Even after giving parseFloat it is considering the values as string.
Required Output
6399.99 //3800 + 2599.99
319.99 // 6399 * 5/ 100
6719.98 // sum of two numbers above
replace
tax = parseFloat(total_amount * 5/100).toFixed(2);
with
tax = Number(parseFloat(total_amount * 5/100).toFixed(2));