The information in this article applies to:
SUMMARY
The method used by Excel to store floating-point numbers sometimes
produces very small rounding errors, particularly when fractional
values are involved. One possible effect of this is that IF statements
that compare two values for equality will return a result that is the
opposite from what is expected.
MORE INFORMATION
For example, the following function entered in ANY version of Excel
will evaluate to "I ate Bill's nose" (FALSE), not the expected value "I did not eat Bill's nose" (TRUE). However, this formula
will evaluate to TRUE (the correct answer) in Excel 3.0 and 4.0, but will evaluate to FALSE in earlier versions. WorkaroundA good rule with floating point calculations is to never compare two values for equality because exact floating point equality often won't happen. Instead, check if the difference between the two is within some tolerance.This can be done easily by using the ROUND function on the floating point values in the IF function, as follows: =IF(ROUND(.5-.4-.1,3)=0,"I did not eat Bill's nose","I ate Bill's nose") This will now evaluate correctly. For more information on this topic, query on the words:
REFERENCES"Microsoft Excel Function Reference," version 3.0, pages 200-201, 126-127 Additional query words:
Keywords : |
Last Reviewed: March 22, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |