strange addition??

%3CLINGO-SUB%20id%3D%22lingo-sub-2044876%22%20slang%3D%22en-US%22%3Estrange%20addition%3F%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2044876%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20setting%20up%20a%20column%20with%206000%20rows%20with%20values%20from%20150%20to%20750%20by%20increments%20of%200.1%20so%20I%20put%20150%20in%20row%202%20(cell%20A2)%20%2C%20150.1%20in%20row%203%2C%20150.2%20in%20row%204%20%26amp%3B%20then%20selected%20the%20series%20and%20sent%20down%20to%206002%20(autoaddition).%26nbsp%3B%20Value%20in%20row%206002%20looks%20like%20750%20but%20if%20I%20click%20on%20it%2C%26nbsp%3B%20in%20the%20formula%20bar%20%2C%20it%20actually%20displays%20749.999999999966%20%26amp%3B%20this%20value%20is%20used%20if%20I%20multiply%20it%20etc.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20tried%20a%20different%20way.%26nbsp%3B%20I%20put%20150%20in%20the%20second%20row%26nbsp%3B%20and%20below%20wrote%20equation%20%3D%20A2%2B0.1%26nbsp%3B%20%26amp%3B%20send%20this%20down%20to%20A6002.%26nbsp%3B%20Value%20in%20row%206002%20is%20750.000000000106.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20format%20numbers%20to%2020%20decimal%20places%20it%20first%20is%20incorrect%20at%20row%2090%20(88%20sequential%20calculations)%20by%20both%20methods%20and%20it%20is%20%3CSTRONG%3Elower%3C%2FSTRONG%3E%20by%200.0000000000001%20by%20both%20methods%2C%20even%20though%20the%20second%20method%20progresses%20to%20provide%20a%20mistake%20of%20inflation.%26nbsp%3B%20Same%20if%20I%20format%20numbers%20to%2030%20decimals%20(max%20allowed)%20-%20it%20is%20accurate%20for%2087%20calculations%20%26amp%3B%20then%20-%20so%20not%20an%20inaccuracy%20of%20proportions%20completely.%3C%2FP%3E%3CP%3EI%20know%20this%20won't%20make%20a%20difference%26nbsp%3B%20when%20I%20round%20things%20but%20wouldn't%20it%20be%20easier%20for%20the%20program%20to%20add%200.1%20accurately%3F%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2044876%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2044912%22%20slang%3D%22en-US%22%3ERe%3A%20strange%20addition%3F%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2044912%22%20slang%3D%22en-US%22%3EIt's%20precision%20error%20due%20to%20floating%20point%20math%20and%20binary%20fractions.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Ftroubleshoot%2Fexcel%2Ffloating-point-arithmetic-inaccurate-result%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Ftroubleshoot%2Fexcel%2Ffloating-point-arithmetic-inaccurate-result%3C%2FA%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

I am setting up a column with 6000 rows with values from 150 to 750 by increments of 0.1 so I put 150 in row 2 (cell A2) , 150.1 in row 3, 150.2 in row 4 & then selected the series and sent down to 6002 (autoaddition).  Value in row 6002 looks like 750 but if I click on it,  in the formula bar , it actually displays 749.999999999966 & this value is used if I multiply it etc.  

 

So I tried a different way.  I put 150 in the second row  and below wrote equation = A2+0.1  & send this down to A6002.  Value in row 6002 is 750.000000000106.  

If I format numbers to 20 decimal places it first is incorrect at row 90 (88 sequential calculations) by both methods and it is lower by 0.0000000000001 by both methods, even though the second method progresses to provide a mistake of inflation.  Same if I format numbers to 30 decimals (max allowed) - it is accurate for 87 calculations & then - so not an inaccuracy of proportions completely.

I know this won't make a difference  when I round things but wouldn't it be easier for the program to add 0.1 accurately?? 

 

2 Replies
It's precision error due to floating point math and binary fractions.

https://docs.microsoft.com/en-us/office/troubleshoot/excel/floating-point-arithmetic-inaccurate-resu...

@brewsdltn   Put very simply, most decimal fractions cannot be represented exactly in binary floating-point, which is how values are represented internally.  And the binary approximation of a particular decimal fraction might differ depending on the magnitude of the number.

 

Consequently, for example, IF(10.01 - 10 = 0.01, TRUE) returns FALSE(!) because the approximation of 1/100 in 10.01 differs from the approximation of 1/100 by itself.

 

For that reason, whenever we expect a calculation that involves or might result in decimal fractions to be accurate to some number of decimal places, we should explicitly round to that number of decimal places -- and not to an arbitrary number like 10, as some people suggest.

 

So, the formulas in column C should be of the form =ROUND(C2+0.1, 1) in C3.

 

The decision of when to round within an expression is subjective.  Only you can make that decision.

 

-----

 

In the case of 10.01 - 10, we can see the infinitesimal difference; Excel displays 0.00999999999999979 when formatted appropriately.

 

(But note: even that is not the exact decimal value.)

 

But often we cannot see the difference, because Excel formats only the first 15 significant digits.

 

(And for that reason, it is sufficient to format your values with 12 decimal places, not 30, since the magnitude (integer part) of your values is 3 digits.)

 

We can see the infinitesimal difference between the displayed value and the actual value by entering formulas of the form =SUM(C3,-(C3&"")) into D3, formatted as Scientific, and copy down the column.

 

Thus, we can see infinitesimal differences as early as D5.

 

Why (C3&"")?  Because that returns a string that is formatted to 15 significant digits.

 

Why SUM instead of =C3-(C3&"")?  Because Excel plays tricks in order to try to hide the infinitesimal conditions sometimes.  In very limited circumstances, Excel replaces the actual arithmetic result with exactly zero (0.00E+00).  Consequently, we do not see infinitesimal differences until D40.

 

But Excel applies that trick inconsistently.  Consequently, for example, =C5-(C5&"") returns exactly zero, but IF(C5-(C5&"") = 0, TRUE) returns FALSE(!).

 

And even the SUM function applies the trick inconsistently.  depending on the form of the parameters.  I just know that SUM(C5,-(C5&"")) always returns the exact arithmetic result.

 

------

 

Re: ``wouldn't it be easier for the program to add 0.1 accurately?``

 

No.

 

First, that is the way that Intel-compatible CPUs behave, as do most other modern CPUs.  And for that reason, most applications have the same problem.  So, Excel would have to do additional work in order to "correct" the binary arithmetic anomalies.  (Or choose a different internal representation, which is what Windows Calculator does.)

 

Second, it is unclear when Excel should automatically round arithmetic results.  For example, if Excel rounded each arithmetic operation, (1/3)*3 would result in 0.999999999999999, not exactly 1.

 

Finally, it is unclear what precision Excel should round to.  For example, if Excel always rounded to 15 significant digits (as most documentation incorrectly claims that Excel does), 10.01 - 10 would still result in 0.00999999999999979.

 

In fact, Excel does provide an option ("Precision as displayed") that attempts to address these issues.  It causes Excel to round the result of a formula to the number of decimal places in the cell format.  But since PAD applies only to formulas, it would not correct the problem with IF(10.01 - 10 = 0.01, TRUE).

 

Caveat:  I deprecate the setting of PAD.  But if you want to experiment with it, be sure to make a copy of the Excel file first.  Merely setting PAD can change constants irreversibly anywhere in the workbook, if their cell format has less precision than the original constant.  That is not uncommon with interest rates, for example.