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

83
Visualizações
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 Respostas
Responde à pergunta

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 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