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

271
Vistas
NodeJs calculation gone wrong

I have if statement like:

if((gotPrice * price.value).toFixed(0) >= answers.MINIMUM_BUY_AMOUNT) {
   ...
}

Results are

(gotPrice * price.value).toFixed(0) = 0

and

answers.MINIMUM_BUY_AMOUNT = 200

Then it fall to true! not sure in what world 0 is greater or equal to 200!!

I also tried this way but results was the same

if((gotPrice * price.value).toFixed(0) >= Number(answers.MINIMUM_BUY_AMOUNT).toFixed(0)) {
   ...
}

sample:

var x = 0.3431;
var y = 1.5467;
var z = '200';
console.log((x * y).toFixed(0) >= z); // false (but in my case says true!)

Any suggestions?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

ToFixed converts number to string, calculations should be done with numbers

var x = 0.3431;
var y = 1.5467;
var z = parseInt('200');

console.log(Math.round(x * y) >= z);
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