Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda