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

209
Views
Why does equation inside While() loop deducts slightly different value than it is defined inside equation?

I have a While() loop like below. It should decrease "change" value by defined value depending on some condition.

while (change - divider >= 0 && physicalCash[i][1] - divider >= 0) {
    physicalCash[i][1] -= divider
    change = change - divider
    tempVal += divider
    console.log("-" + divider)
    console.log(change)
}

Here is the result of above code, question is why instead of 20 it deducts 20,000000000005 after first iteration of while loop:

96.74
-20
76.74
-20
56.739999999999995
-20
36.739999999999995
-10
26.739999999999995
-10
16.739999999999995
-5
11.739999999999995
-5
6.739999999999995
about 4 years ago · Juan Pablo Isaza
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!