• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel and floating point problem?

Xiq

Active Member
Hello everyone, its been a while since my last post on this forum :)

I found a frustrating problem (first time I noticed this after all these years using Excel), for example:
Code:
=5.1-5
I would expect the result to be exactly 0.1
however Excel is returning 0.0999999999999996

So my test:
Code:
=5.1-5=0.1
Will of course return FALSE...

I assume this has to do something with floating point stuff (see here a MS support page).

Is there a better solution to this problem, other than using the ROUND function and hardcode the number of decimals to round? Using the "Precision as displayed" option sounds a bit tricky to use in my opinion.
 
Hi ,

You can test out certain values of the low value , 0.1 in your example.

The problem exists till a decimal value of less than 0.5.

Once the low value is 0.5 or above , the problem does not exist.

Thus , even a subtraction of 99999999999999.5 - 99999999999999 returns the correct value of 0.5

The moment the low value becomes less than 0.5 , say 0.49 , then the result of :

9999999999999.49 - 9999999999999

does not equal 0.49

One solution is to multiply by 10 or even 10000 , and then divide the result by 10 or 10000 ; this will give you the correct result.

Thus , =(9999999999999.49 * 100 - 9999999999999 * 100) / 100 will correctly return 0.49

Narayan
 
Last edited:
Hi NARAYANK991,

Unfortunately this is not a solution that works 100% of the time.

For example:
Code:
=64.6*1000-64*1000=0.6*1000
Will return:
Code:
=599.999999999993=600

I've attached a test with 1k comparisons.
 

Attachments

  • Excel floating point Problem Test - 20180302.xlsx
    58.6 KB · Views: 1
Back
Top