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

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

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