I still don't quite understand why Meow's first column was fine but the second wasn't, and also why I couldn't reproduce his sum.
I actually just tried doing it again and I also got 0.00 whether the positive number was on the top of bottom of the list. So who knows.
I suspect that you are both making the mistake of looking at the
formatted results, not the
actual cell value.
Be sure that B21 (SUM formula in the second column) is
formatted at General (or Scientific)
after entering the formula.
In Meow's second attempt, B21 appears to be
formatted as Number with 2 decimal places (0.00
sic).
Generally, when looking at anomalies of floating-point arithmetic, I suggest that you temporarily format the cells in question
as Scientific (with 2 decimal places, the default).
That is the only way to be sure that what
appears to be zero is (or is not) truly exactly zero (0.00E+00).
Caveat: We must
reapply the Scientific format
each time after entering the formula, in order to override Excel's autoformatting heuristics (sigh). Alternatively, format all of A1:A20 as Number with 2 decimal places.
Although Fluff is correct that non-integer arithmetic can have different results due to order because of 64-bit binary floating-point anomalies, the exact zero in A21 (SUM of the first column) is
an illusion created by arbitrary and dubious tricks that Excel applies inconstently in a poorly-conceived attempt to hide (some) floating-point anomalies.
These tricks are alluded to in the section titled (misleadingly) "Example when a value reaches zero" in the webpage that Fluff cites.
To demonstrate, change the simple formula in A21 (presumably =SUM(A1:A20) to
=SUM(SUM(A1:A19),--A20) , then (
afterward) format A21 as Scientific.
The result is about 5.68E-14. Still different from about -3.06E-14 for =SUM(B1:B20) presumably in B21.
But not exactly zero (0.00E+00).
However, note that all of the following formulas do result in
exactly zero (!): =SUM(A1:A20), =SUM(A1:A19,A20), =SUM(A1:A19,--A20) and =SUM(SUM(A1:A19),A20) .
Of course, there is no good reason for the difference, based on the 64-bit binary floating-point standard.
Instead, the explanation is that the SUM function is doing "funny things" based on the nature of the parameters.
To demonstrate that this is an anomaly of Excel SUM, contrast with "vbsum" functions in the example below.
The general "remedy" (workaround to avoid such differences) is: whenever you expect a calculation that involves non-integers to be accurate to some precision,
explicitly round to that precision -- and
not to arbitrary number of decimal places like 10, as some people suggest.
Your formulas should be
=ROUND(SUM(A1:A20),2) and
=ROUND(SUM(B1:B20,2) .
-----
Excel v. VBA calculations
To demonstrate that the different results of the various SUM formulas are due to anomalies of the Excel SUM implementation and not 64-bit binary floating-point standard, the following compares the Excel SUM results in columns A and B with the results of similar VBA functions in columns C and D.
Columns A and B use Excel to calculation the sums of A1:A20 and B1:B20 in different ways.
Columns C and D use VBA functions to do similar calculations.
Note that the VBA results are consistent in each column, regardless of method of summing.
For the most part, the difference between the results in columns C and D is the order of the operands, which is an anomaly of 64-bit binary floating-point.
However, the difference in row 26 is due to the fact that, for Intel-compatible CPUs, VBA uses the intermediate
80-bit floating-point internal results whenever possible for a series of type Double calculations. (And not for calculaltions with type Variant operands, even if they contain type Double values.)