A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Does anyone know a way to detect if a result has been miscalculated?
I do not agree that the calculation is wrong. IMHO, only your perception of it is wrong because Excel only formats up to the first 15 significant digits (rounded), which is an arbitrary choice.
I can explain better (and more simply than any cited references). But I don't have time at the moment.
To answer your immediate question....
- Temporarily, format the cell value so that it displays 15 significant digits.
Shortcut: Highlight the calculation (it might be a subexpression) in the Formula Bar and press the f9 key. Caveat: Be sure topress Esc afterwards, not Enter. Otherwise, the formula will be changed irreversibly.
For example, if your values in A1 and A2 are constants, not the result of a calculation (even if you did copy-and-pasted value), when we format A3 with 13 decimal places, we see 29.3999999999996 instead of 29.4000000000000.
But sometimes, the infinitesimal difference is so small that we cannot see it because of Excel's arbitrary formatting limitation.
So, more generally....
- =MATCH(--TEXT(A3,"0.00000000000000E+0"), A3, 0) returns #N/A when the binary representation of A3 is not the same as the binary representation A3 rounded to 15 significant digits.
We cannot do simply =A3=--TEXT(A3,"0.00000000000000E+0") because in Excel, the "=" operator rounds the left and right expressions to 15 significant digits for the purpose of the comparison.
- =A3-TEXT(A3,"0.00000000000000E+0")-0, formatted as Scientific, displays the infinitesimal difference between the two binary representations.
We cannot do simply =A3-TEXT(A3,"0.00000000000000E+0") because sometimes (and inconsistently), Excel replaces the actual arithmetic result with exactly zero (0.00E+00 when formatted as Scientific) in order to hide the infinitesimal difference.
That is incompletely described under the misleading title "Example when a value reaches zero" in https://support.microsoft.com/en-us/help/78113/floating-point-arithmetic-may-give-inaccurate-results-in-excel .
Of course, the redundant -0 should not make any difference. But it does! That demonstrates just how inconsistently Excel applies the rule. (To be fair, it demonstrates that I simplified the conditions of the rule to some degreee. There is more to it.)