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

175
Views
JavaScript not adding float values properly?

I've been having an issue with my JavaScript code where in the final verification step of a form, it sums the values to determine whether or not their total sum is equivalent to 100. Normally, it works as intended, but occasionally it will indicate that there is an issue if, for example, the values are: 9.325210871602625 and 90.67478912839736. These values' sum should be accepted, yet it is not.

As far as I can tell, the calculations that are performed to acquire these values are correct so I do not believe that they are the source of error, and frankly there is far too much code involved in calculating their values to display here anyway.

Obviously I could just loosen the requirements so that any value that falls in the range of (99.99 - 100.01) would be accepted such as:

let valuesOK = sumValues("example") > 99.99 && sumValues("example1") < 100.01;

but that doesn't seem like a proper solution.

My only theory is that because both numbers have 16 digits in the case that I provided (9.325210871602625 and 90.67478912839736), however because 9.325... has one extra decimal place than 90.674..., that that may be causing problems when adding them together. Regardless, I'm not sure how to elegantly solve that issue if my theory is indeed correct.

I'd appreciate any help or references to documentation that might make sense of my issue.

about 4 years ago · Juan Pablo Isaza
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!