Issue with Equation Evaluating Incorrectly When Adding Fifth Term

%3CLINGO-SUB%20id%3D%22lingo-sub-1921196%22%20slang%3D%22en-US%22%3EIssue%20with%20Equation%20Evaluating%20Incorrectly%20When%20Adding%20Fifth%20Term%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1921196%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20currently%20working%20on%20an%20equation%20in%20my%20excel%20sheet%20where%20I%20am%20adding%20a%20series%20of%20values%20based%20on%20if%20statements%20that%20check%20if%20a%20cell%20is%20blank%20or%20not.%20I%20currently%20have%204%20of%20the%208%20if%20statements%20inputted%20into%20the%20equation%2C%20and%20it%20is%20correctly%20evaluating%20to%200.%20However%2C%20as%20soon%20as%20I%20add%200%20to%20that%2C%20it%20suddenly%20evaluates%20to%20-8.88E-16%2C%20which%20after%20checking%20the%20math%20by%20hand%2C%20is%20incorrect.%20If%20I%20add%20any%20value%20other%20than%200%2C%20it%20evaluates%20correctly%20though.%20The%20equation%20I%20am%20currently%20using%20(in%20cell%20J15)%20is%20listed%20below.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3DIF(ISBLANK(%24D%2413)%2C0%2CG3*(%24D%2450-%24D%2449))%2BIF(ISBLANK(%24D%2414)%2C0%2CK3*(%24D%2451-%24D%2450))%2BIF(ISBLANK(%24D%2415)%2C0%2CO3*(%24D%2452-%24D%2451))%2BIF(ISBLANK(%24D%2416)%2C0%2CS3*(%24D%2453-%24D%2452))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20Is%20currently%20evaluating%20to%20%3CSTRONG%3E0.00E%2B00.%3C%2FSTRONG%3E%20However%2C%20the%20simple%20modification%20below%20alters%20that%20value%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3DIF(ISBLANK(%24D%2413)%2C0%2CG3*(%24D%2450-%24D%2449))%2BIF(ISBLANK(%24D%2414)%2C0%2CK3*(%24D%2451-%24D%2450))%2BIF(ISBLANK(%24D%2415)%2C0%2CO3*(%24D%2452-%24D%2451))%2BIF(ISBLANK(%24D%2416)%2C0%2CS3*(%24D%2453-%24D%2452))%3CU%3E%3CSTRONG%3E%2B0%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20Equation%20leads%20to%20the%20value%20of%20%3CSTRONG%3E-8.88E-16.%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20appreciate%20any%20assistance%20in%20solving%20this%20problem%2C%20thank%20you!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3EThe%20excel%20file%20is%20attached.%20The%20cell%20I%20am%20trying%20to%20fix%20is%20J15%2C%20which%20will%20be%20used%20to%20populate%20the%20surrounding%208%20cells.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1921196%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1921253%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20Equation%20Evaluating%20Incorrectly%20When%20Adding%20Fifth%20Term%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1921253%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F877559%22%20target%3D%22_blank%22%3E%40KevinHj%3C%2FA%3E%26nbsp%3BCheck%20out%20this%20link.%20And%20you%20can%20Google%20for%20more%20explanations%20of%20the%20issue.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fblog%2F2008%2F04%2F10%2Funderstanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fmicrosoft-365%2Fblog%2F2008%2F04%2F10%2Funderstanding-floating-point-precision-aka-why-does-excel-give-me-seemingly-wrong-answers%2F%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20other%20words%2C%20Excel%20may%20give%20seemingly%20incorrect%20answers.%20Your%20%22incorrect%22%20number%20is%20still%20zero%20up%20to%2015%20decimals.%20Wrap%20the%20formula%20in%20a%20ROUND%20function.%20For%20example%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3DROUND(%3CYOUR%20formula%3D%22%22%3E%2C14)%3C%2FYOUR%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3Eand%20the%20answer%20will%20be%200.00%2B00E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1921784%22%20slang%3D%22en-US%22%3ERe%3A%20Issue%20with%20Equation%20Evaluating%20Incorrectly%20When%20Adding%20Fifth%20Term%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1921784%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F877559%22%20target%3D%22_blank%22%3E%40KevinHj%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOf%20course%2C%20simply%20adding%20zero%20should%20not%20change%20the%20actual%20arithmetic%20result.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20it%20does%20affect%20the%20arbitrary%20behavior%20of%20a%20dubious%20rule%20that%20Excel%20implements%20inconsistently%20in%20a%20misguided%20effort%20to%20minimize%20the%20effects%20of%2064-bit%20binary%20floating-point%20arithemetic.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20general%2C%20it%20is%20prudent%20to%20explicitly%20round%20calculations%20that%20you%20expect%20to%20be%20accurate%20to%20some%20number%20of%20decimal%20places%20(use%20ROUND)%20or%20significant%20digits%20(use%20TEXT%2C%20converted%20to%20a%20number).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-----%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20difference%20when%20zero%20is%20added%20is%20hinted%20at%20in%20the%20poor%20explanation%20under%20the%20misleading%20title%20%22Example%20when%20a%20value%20reaches%20zero%22%26nbsp%3B%20in%20the%20document%20at%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Ftroubleshoot%2Fexcel%2Ffloating-point-arithmetic-inaccurate-result%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EBinary%20Arithmetic%20Anomalies%3C%2FA%3E%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20a%20nutshell%2C%20when%20the%20last%20operation%20of%20a%20formula%20is%20subtraction%20(or%20addition%20of%20oppositely-signed%20values)%2C%20and%20the%20magnitudes%20of%20the%20two%20non-zero%20operands%20are%20%22close%20enough%22%2C%20Excel%20arbitrarily%20replaces%20the%20actual%20arithmetic%20result%20with%20exact%20zero%20(0.00E%2B00).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20we%20add%20zero%2C%20that%20rule%20no%20longer%20applies%20because%20the%20last%20operation%20is%20not%20a%20subtraction%20of%20two%20non-zero%20operands.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBTW%2C%20the%20rule%20no%20longer%20applies%20even%20when%20we%20simply%20put%20parentheses%20around%20the%20entire%20expression.%26nbsp%3B%20Using%20MSFT's%20example%2C%20%3D1.333%2B1.225-1.333-1.225%20results%20in%20exact%20zero%2C%20but%20%3D%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3E(%3C%2FSTRONG%3E%3C%2FFONT%3E1.333%2B1.225-1.333-1.225%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3E)%3C%2FSTRONG%3E%3C%2FFONT%3E%20results%20in%20-2.22E-16.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20be%20forewarned%3A%26nbsp%3B%20The%20SUM%20function%20is%20not%20consistent%20about%20when%20it%20does%20and%20does%20not%20apply%20the%20rule%20internally.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

I am currently working on an equation in my excel sheet where I am adding a series of values based on if statements that check if a cell is blank or not. I currently have 4 of the 8 if statements inputted into the equation, and it is correctly evaluating to 0. However, as soon as I add 0 to that, it suddenly evaluates to -8.88E-16, which after checking the math by hand, is incorrect. If I add any value other than 0, it evaluates correctly though. The equation I am currently using (in cell J15) is listed below.

=IF(ISBLANK($D$13),0,G3*($D$50-$D$49))+IF(ISBLANK($D$14),0,K3*($D$51-$D$50))+IF(ISBLANK($D$15),0,O3*($D$52-$D$51))+IF(ISBLANK($D$16),0,S3*($D$53-$D$52))

 

This Is currently evaluating to 0.00E+00. However, the simple modification below alters that value:

 

=IF(ISBLANK($D$13),0,G3*($D$50-$D$49))+IF(ISBLANK($D$14),0,K3*($D$51-$D$50))+IF(ISBLANK($D$15),0,O3*($D$52-$D$51))+IF(ISBLANK($D$16),0,S3*($D$53-$D$52))+0

 

This Equation leads to the value of -8.88E-16. 

 

I would appreciate any assistance in solving this problem, thank you!

 

 

The excel file is attached. The cell I am trying to fix is J15, which will be used to populate the surrounding 8 cells.

 

2 Replies
Highlighted

@KevinHj Check out this link. And you can Google for more explanations of the issue.

https://www.microsoft.com/en-us/microsoft-365/blog/2008/04/10/understanding-floating-point-precision... 

In other words, Excel may give seemingly incorrect answers. Your "incorrect" number is still zero up to 15 decimals. Wrap the formula in a ROUND function. For example:

=ROUND(<your formula>,14)

and the answer will be 0.00+00E

Highlighted

@KevinHj  

 

Of course, simply adding zero should not change the actual arithmetic result.

 

But it does affect the arbitrary behavior of a dubious rule that Excel implements inconsistently in a misguided effort to minimize the effects of 64-bit binary floating-point arithemetic.

 

In general, it is prudent to explicitly round calculations that you expect to be accurate to some number of decimal places (use ROUND) or significant digits (use TEXT, converted to a number).

 

-----

 

The difference when zero is added is hinted at in the poor explanation under the misleading title "Example when a value reaches zero"  in the document at Binary Arithmetic Anomalies .

 

In a nutshell, when the last operation of a formula is subtraction (or addition of oppositely-signed values), and the magnitudes of the two non-zero operands are "close enough", Excel arbitrarily replaces the actual arithmetic result with exact zero (0.00E+00).

 

When we add zero, that rule no longer applies because the last operation is not a subtraction of two non-zero operands.

 

BTW, the rule no longer applies even when we simply put parentheses around the entire expression.  Using MSFT's example, =1.333+1.225-1.333-1.225 results in exact zero, but =(1.333+1.225-1.333-1.225) results in -2.22E-16.

 

And be forewarned:  The SUM function is not consistent about when it does and does not apply the rule internally.