Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!