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

132
Visualizações
Oddities with big integers in JavaScript

I was doing some problems on Leetcode, this one in particular, and I noticed some oddities with how JavaScript handles bigger numbers:

> x = 1000000000000000000000000000001;
1e+30 // Scientific notation? interesting

> x.toString()
'1e+30' // Reason for the parsing issues with my Leetcode implementation..

> x.toLocaleString('en', { useGrouping: false });
'1000000000000000000000000000000' // The last '1' was changed to a '0', probably cause x is stored as 1e+30.

> BigInt(x).toString();
'1000000000000000019884624838656' // ?

> y = 2384762348723648237462348;
2.3847623487236483e+24 // This big number is stored as a floating point?

I tried the string casting of x in Python, and it worked just fine, so I'm assuming this behavior is unique to JavaScript? I'm not too familiar with how JavaScript does things under the hood, so I was hoping I could get an explanation for what's going on here with JavaScript numbers and BigInt? And how would one store x and cast it into a string?

Thanks!

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