-1

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?

user1285928
  • 1,328
  • 29
  • 98
  • 147

1 Answers1

1

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
Andru
  • 7,011
  • 3
  • 21
  • 25