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

200
Visualizações
How to calculate a high large number in js?

I am trying to calculate a result and I want that in int.

calculation =>

   const amount = 2000 * 10 ** 18
    // Result I am Getiing is 2e+21
    
    console.log(amount);

I also tried the calculation in Math.floor(Number()) But still no success. Is there a way so I can make this calculation and get the real output in just numbers (like 2000000000000000000000) I need to pass this in an API and unfortunately that API parameter is int only.

Remark:- I am not looking for a BigInt solution

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

0

You can use BigInt.

// given amount comes from a library you have no control over
const amount = 2000 * 10 ** 18;

const bigInt = BigInt(amount);

// BigInt also has a toString utility method
console.log(bigInt.toString()); // 2000000000000000000000

// use BigInt directly when you are in control
const amount = 2000n * 10n ** 18n;

console.log(typeof amount);
console.log(amount.toString()); // 2000000000000000000000

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