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

121
Visualizações
JavaScript Division on floating returns strange result

I am building a Metrics Converter site where precise calculations matter a lot and I noticed a strange issue when performing these metrics calculations.

Let me post a few instances which I have come across and any solution would be appreciated.

I have a Centimeter to Meter Conversion Page where I take the user input and divide by 100 to get the meter output. It works properly except for a few strange numbers.

Eg - 0.009 cm would be 0.00009 Meters

The formula used would be 0.009/100 = 0.00009 Meters

However, JavaScript returns a weird result

  1. 0.009/100 returns as 0.00008999999999999999
  2. 0.007/100 returns as 0.00007000000000000001
  3. 0.00009/100 returns as 9.000000000000001e-7

The same can be verified in the console or on the website cm to meters also by providing the centimeter value.

Now the site requires precise calculations for these metrics/units it would be a bad experience to use if it displays a strange result with long numbers. I am sure that it will happen with many other floating point numbers and other conversion formulas that is been used.

I have noticed the same is not happening in Python, C# language as it returns accurately.

Any solutions or workaround is appreciated to solve this issue

about 4 years ago · Santiago Gelvez
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