I am aware of the general problem of numerical inaccuracies with floating point numbers, but I would expect Excel and Google Sheets to behave the same. Unfortunately, they don\'
The following observations were made on Google Sheets (web version on 2020-07-02 with Safari 12.1.2 on macOS 10.14.6), Microsoft Excel 2008 for Mac 12.3.6, and Numbers 10.0. In Excel, Preferences… > Calculation > “Set precision as displayed” was disabled.
Cells were set:
15.525
.=3*5.175
.=A2=A1
.=A2-A1
.=(A2-A1)
.=A4*1000000000000000
.=A5*1000000000000000
.=(1/3*3-1)*POWER(10,34)
.The observed results were:
If the cell formats are changed from Automatic to Scientific, then the Google Sheets results change:
Otherwise, there are no changes in other cells or spreadsheets except cosmetic changes, such as showing “0.00E+00” instead of “0”.
The above observations are consistent with:
The −1.776356839•10−15 value observed in Google Sheets and Excel is characteristic of the IEEE-754 64-bit binary format, so it seems quite likely they are using that format. The −10−34 value observed in Numbers is less conclusive, so the hypothesis it is using a decimal format should be investigated further.
The above notes rounding in Excel for numbers near zero, with the post-rounded value used in further calculations. Another experiment would be to construct a number that is not one but that displays as one yet has a simple formula and then use that cell in further calculations to see if the pre-rounding or post-rounding value is used.
Cells were set:
=1/49*49-1
.=1/49*49
.=B2-1
.49 was chosen because, when evaluated with IEEE-754 binary64, 1/49*49
yields a number slightly under 1. (This does not occur with smaller denominators, such as with 1/3*3
because, although there is a rounding in the division, there is also a rounding in the multiplication that compensates, producing a result of exactly 1. 49 is the smallest integer for which this does not occur.)
Results, with Scientific formatting:
Again, Google Sheets seems to use IEEE-754 with no shenanigans. Excel appears to have rounded the results. However, if parentheses are added, setting B1 to =(1/49*49-1)
or B3 to =(B2-1)
, Excel displays “-1.11E-16”. This is consistent with rounding being disabled when parentheses were used in the first set of observations.
However, now we see some shenanigans in Numbers for the first time. We would expect B1 and B3 to show the same result, but they do not. Hypothesis: Numbers uses more precision within a formula but less for the final result of a cell?
The B1 result is consistent with 34 decimal digits. To 34 significant decimal digits, 1/49 is 02040816326530612244897959183673469. Then 49 times that is .99999999999999999999999999999999981. Rounding to 34 significant digits gives .9999999999999999999999999999999998, and then subtracting 1 gives −2•10−34.
Further experimentation, not detailed here, suggests Numbers calculates internally with 34 decimal digits but rounds the final cell value to 15 decimal digits and uses that for display and for further calculation.