Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda