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

180
Views
Reduce a number with some limit

I use this code to reduce amount with a small amount:

const transfer = async (  
  amount: string
): Promise<void> => {
  
  if (parseFloat(amount) <= 0.01) {
    amount = String((2 / 100) * parseFloat(amount));
  }

  // More code here...
}

As I result I would like to get for example from 0.0000054 the result 0.0000053. But what if we have huge number like 100000000.0 The calculated percentage is too hight.

Is there some other way to reduce the number but with some very small amount no matter is it a huge or very small amount? For example is it possible to use some function which will reduce the amount with the next available number?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I'm not entirely confident I understand what you're asking, but I think Math.max and Math.min might be what you're looking for?

function bound(lower, upper, input) {
  return Math.max(lower, Math.min(upper, input));
}

console.log( bound(0, 100, 200) ); // > 100
console.log( bound(0, 100, -200) ); // > 0

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!