Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
Why is JavaScript not converting number to floating numbers?

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
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

replace

tax = parseFloat(total_amount * 5/100).toFixed(2);

with

tax = Number(parseFloat(total_amount * 5/100).toFixed(2));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!