Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda