Forum Discussion
Serious bug with certain decimal numbers: Countifs and Roundup failed
- May 02, 2021
In addition, Excel works by default with 15 digits and many functions ignore extra digits, but some work in background with 17 digits. More about that is here 17 or 15 digits of precision - Excel Tips - MrExcel Publishing
For this particular case if use
=SUMPRODUCT( ($C$1:$C$11<=C4)*($B$1:$B$11=B4))
instead of COUNTIFS() it returns correct result.
I think there are two separate issues, and it is unclear if the issue that you focused on is truly important for your purposes -- although it is interesting curiosity.
-----
Yes, Excel has a formatting defect that causes 43863.89142 to be displayed as 43863.8914199999, for example.
(MSFT used to document the defect in KB161234. But I cannot find that document or the equivalent online anymore. No matter. The KB description was inaccurate, anyway.)
The defect is specific to Excel. It has nothing to do with the 64-bit binary floating-point standard. That is why you do not see it in other applications.
And the formatting defect is not limited to ROUNDUP. The formatting defect arises with relatively few binary values that meet very specific conditions. (I can explain, if you wish. It is TMI for most people.)
Moreover, the effect of the formatting defect can be confusing because when we enter 43863.89142, initially it has the binary value of 43863.89142, even though it appears to be 43863.8914199999. But if we edit the cell, it changes to the binary value of 43863.8914199999, which is different.
For example, initially =ISNUMBER(MATCH(VALUE("43863.89142"), { 43863.89142 }, 0)) returns TRUE, even though it appears to be =ISNUMBER(MATCH(VALUE("43863.89142"), { 43863.8914199999 }, 0)).
But if we select the cell and press f2, then Enter, the formula returns FALSE.
OTOH, if we have =VALUE("43863.89142") in A1, =COUNTIF(A1, "="&43863.89142) always returns zero because COUNTIF sees the string "=43863.8914199999".
The only work-around that I know is to replace such constants with expressions like VALUE("43863.89142"), ROUND("43863.89142",5), A1+"43863.89142", etc.
The key is to enter such numbers in double-quotes in an arithmetic expression, when you encounter the formatting defect.
-----
But the real question is: why are you using ROUNDUP(B4,5), in the first place?
In Sheet1, the date and time constants in column B are already accurate to the second. There is no need to round them.
And if there is a need (for example, for calculated date and time values), rounding to 5 decimal places is the wrong way to do it.
Instead, you might use one of the following, depending on your requirements.
TEXT(B4, "m/d/yyyy h:m:s")
or
--TEXT(B4, "m/d/yyyy h:m:s")
or
INT(B4)+TEXT(B4,"h:m:s")
or
INT(B4)+TEXT(MOD(B4,1),"[h]:m:s")
If you provide the original use of COUNTIFS that led to the problem, we can be more specific.
I think what you posted in your attachment is your attempts to understand and work around the original problem. I "cannot see the forest for the trees".
The only work-around that I know is to replace such constants with expressions like VALUE("43863.89142"), ROUND("43863.89142",5), A1+"43863.89142", etc.
The key is to enter such numbers in double-quotes in an arithmetic expression, when you encounter the formatting defect.
Interesting. I've never sever such a workaround before. Will keep it in mind.