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

182
Vistas
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 Respuestas
Responde la pregunta

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