COUNTIF Bug?

This started in a post about MAXIF where I used COUNTIFS to find max values. The screenshot below uses a simpler formula that shows the problem. In cell B1 of each table is =COUNTIF(A,">"&A1) and that is filled down to the other rows. It should give the number of rows that have values greater than the value in the current row. However, for numbers that end in 1/3, it appears that it incorrectly thinks the number in the current row is greater than itself and the answer is higher by 1.


Am I doing something wrong or is this a bug?


User uploaded file

Posted on Dec 16, 2015 6:42 PM

Reply
7 replies

Dec 17, 2015 12:27 AM in response to Badunit

I'm not sure I'd call it a bug.

What appears to be happening is that "A1" extracts the displayed (or possibly the maximum precision possible to be displayed) number in the cell, but this is compared to the (more precise) calculated and stored value in the cells including the one displaying 4.?...


Numbers displayed in cells on Numbers tables have a maximum (base 10) precision of 15 digits. Numbers that are the result of a calculation have, If I recall correctly, a maximum (base 10) precision of 19 digits.


Whether the displayed number is larger or smaller than the same number expressed to a precision finer by 10^4 depends on the direction it is rounded at the 15th digit. If the rounding is down, the effect is the same as truncating the number after the fifteenth digit—the added value of any digits after the fifteenth is lost, and the displayed number is less than the calculated value. This will always be the case for a positive value which includes 1/3 as a fractional part. For numbers including a fractional part of 2/3, though, the opposite is true: no matter where the repeating decimal representing 2/3 is rounded, the final digit of the rounded value will be a seven, and the displayed (rounded) version will always be larger than the calculation result.


A fractional value of n/7 will produce a similar result.

User uploaded file

In this case, n = 1, 4, or 5 provided a value that was rounded down at the 15th digit, and was counted as being 'smaller than itself'; values of 2, 3 or 6 in the numerator rounded up, and counted as 'larger than itself.'


Regards,

Barry

Dec 17, 2015 4:11 AM in response to Barry

Barry wrote:


What appears to be happening is that "A1" extracts the displayed (or possibly the maximum precision possible to be displayed) number in the cell, but this is compared to the (more precise) calculated and stored value in the cells including the one displaying 4.?...


That may be the cause but the fact remains that the answer is incorrect.


RANK could work for this simple case but not for what I was originally doing. I simplified my formula here to demonstrate the problem. I was using COUNTIFS in my original formula. Both functions have this problem and I suspect SUMIF, SUMIFS, AVERAGEIF and AVERAGEIFS do too but I have not tested them.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

COUNTIF Bug?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.