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

357
Visualizações
How to convert a decimal number in a hexadecimal number in JavaScript?

let me explain my problem. I used the following method to convert my binary number to decimal number : number.toString(16)

This method renders a number that indeed appears to be in hexadecimal form. But the problem is there: I need from the id of a user that I retrieve via an authentication API (steam in this case), and I need to retrieve data via a third-party SQL database. The identifier of this user on the database is indeed his steam identifier, but in hexadecimal form.

The problem is that the identifier that I retrieve and transform into hexadecimal form is not equal to that of the database. One could then wonder if the identifier of the database is not simply different? And that's where my various tests come in by proving me no!

Let me explain in more detail:

With this code:

let n = 76561199121591748;
console.log(n.toString(16))

The code returns me :

110000145386dc0

This should return me this (which is the database id):

110000145386dc4

According to all my tests (example of online scripts, test of nodejs conversion libraries etc) everything leads me to false results. Still, the online conversions sites (likethis site) show me the good result. So I imagine that the problem must come from the method. Can you tell me if there is an explanation for this? Thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Javascript numbers are IEEE double-precision floats. The set of integers that can be represented exactly are those integers n such that - 253-1 <= n <= 253-1.

The constant Number.MAX_SAFE_INTEGER has the value 253-1, or 9,007,199,254,740,991 decimal.

Your value 76,561,199,121,591,748 is an order of magnitude larger than Number.MAX_SAFE_INTEGER and so can't be represented exactly.

You might take a look at using BigInt instead of Number.

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