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

84
Vistas
adding a percentage to a big integer

I'm making a cookie clicker game where i recently converted the counter from a number primitive to Big-int and i have faced a problem where i need to add a percentage onto a Big-int. Normally if i would like to add 50% of 1000 to 1000 it would be as easy as multiplying 1000 by 1.5 but you cannot do that with Int's. I am open to ideas on how to solve this issue, any bit helps. What I was originally thinking is that I divide it by 100 and then multiply it by 150 which would give the same results, but the problem is that if the original was below 100 then the fact that it is an int would mess this process up.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do that with bigInts too:

const bigIntNum = BigInt(123456);
const multipledByTwo = bigIntNum * 2n;
console.log(multipledByTwo);

But do make sure the number that you are calculating by multiplying should be in the range of bigInt.

To add some percent to the bigInt number, you should write the following code:

const bigIntNum = BigInt(123456);
//adding 50%
const addedFiftyPercent = bigIntNum + (bigIntNum * 50n) / 100n;
//adding x%
const addedXPercent = bigIntNum + (bigIntNum * xn) / 100n;
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