AccessUser wrote:
If the Difference amount (cell C21) is NOT ZERO, then the word BAD should display in column B for all rows.
OTHERWISE if the different amount IS ZERO, then the word GOOD should display in column B for all rows.
First, you wrote your formula backwards. Your formula is, essentially:
IF(INT(D21)<>0, "good", "bad")
It displays "good" when INT(D21) is __not__ zero, not when it __is__ zero.
So your first example seems right to you ("good") only because you thought (0.0000) would truncate to exact zero, when in fact it truncates to -1.
Likewise, the second example truncates to -1. It looks wrong to you ("good" instead of "bad") only because your formula is incorrect. It should be, essentially:
=IF(INT(D21)=0, "good", "bad")
Second, looks can be deceiving due to formatting.
I suspect that you are misinterpreting "$ (0.0000)" as exact zero.
But in the Accounting format, it is a negative value that rounds to zero when displaying 4 decimal places.
(It should round to -0.0001. But that is an unrelated issue.)
In the Accounting format, "$ -" (dollar dash) is exact zero.
So both examples show a non-zero negative value in D21.
And you should expect INT(D21) to be the same value in both examples.
Ergo, you should expect the same result from the IF() expression.
If you want to round or truncate toward zero for negative as well as positive values, you should use ROUND(D21,0) or TRUNC(D21).
Third, it is remarkable that you expect D21 to be exact zero in the first example, if indeed you do, as your follow-up comment suggests, IMHO.
Note that formatting only affects the __appearance__ of a cell value. It does not affect that __actual__ cell value.
(Unless you set the option "Precision as displayed", which I do __not__ recommend.)
Note the SUM(D11:D20) is 7.00075 when formatted to 5 decimal places, the same as column E.
So you should expect a difference of -0.00005 for SUM(D10:D20) in the first example, and a difference of -0.00015 in the second example.
Finally, the reason why D21 does not display -0.0001 and -0.0002 when rounded to 4 decimal places is a quirk of computer binary arithmetic.
If you format D21 as Number with 19 decimal places, you will see that D21 is -0.0000499999999981071 in the first example, not -0.00005.
This is because Excel uses 64-bit binary floating-point to represent numerical values internally. Consequently, most decimal fractions cannot be represented exactly; and the approximate representation of the same decimal fraction might vary depending on the magnitude of the integer part.
This causes infinitesimal anomalies (differences from our expectations based on decimal arithmetic) when we do calculations with decimal fractions and when the result of calculations has a decimal fraction.
For that reason, when we expect a calculation to be accurate to some number of decimal places (5 in your example), we should explicitly round to that number of decimal places. For example, ROUND(SUM(D10:D20),5).