Inconsistent "greater than" and "less than" calculations

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hello, I have a column of cells into which I want to calculate some basic pass/fail criteria based on this formula
Code:
=IF(ISBLANK(C28),"",IF(D28>0.1,"Fail","Pass"))
The data for D28 is coming from another calculation, which is working correctly. If the result of the calculation is exactly 0.1, then most of the time I get a "Pass" return - which is incorrect (0.1 is not greater than 0.1). I say most of the time because although it happens this way most of the time, there are certain cells which give the correct answer.


..any idea what's going on?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Have you increased the no of decimal places to see what the exact value(s) are?
 
Upvote 0
Yes, I increased now to seven decimal places. number is 0.10000000
 
Upvote 0
Yes, I increased now to seven decimal places. number is 0.10000000

What number to you get if you increase it to 14 decimal places? By the way, we are talking about the calculated values, not the fixed 0.1 value.
 
Upvote 0
Hmmm. It seems that at the 15th decimal place, I get the number 1 (therefore, 0.100000000000001). How'd that happen!?
 
Last edited:
Upvote 0
The "trailing 1" (I'll call it for lack of a better term) is in the cell which calculates the 0.100 with this formula:
Code:
=IF(OR(ISBLANK(C29)),"",ABS(C29-A29))
Nothing odd about the reference cells (I took them out to 24 decimal places, and no "trailing 1's")

I changed the formula to a simple =C29-A29, but the "trailing 1" remains, therefore problem still remains.

what in the world is going on?!
 
Upvote 0
Hi Rick, yes I put it there as well, I should have mentioned it in this post. Sorry, I was getting desperate!
 
Upvote 0
The problem is caused by the way computers store decimals.
 
Upvote 0
Hmmm. It seems that at the 15th decimal place, I get the number 1 (therefore, 0.100000000000001). How'd that happen!?
The value 0.1 does not have an exact binary (what computers use) representation, so values that calculate to it end up getting rounded, sometimes up, sometimes down depending on the calculation and sometimes the order of calculations... the "1" you see at the end is the result of that rounding. Why don't you round your calculated values to 10 decimal places and then compare that rounded value to see if it is greater than 0.1 or not.
 
Upvote 0

Forum statistics

Threads
1,221,322
Messages
6,159,227
Members
451,547
Latest member
loop98

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top