18.11.2014 Views

Microsoft Office

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Making Your Worksheets Error-Free 32<br />

You can instruct Excel to use the displayed values by checking the Set Precision As Displayed check box on<br />

the Advanced section of the Excel Options dialog box. (Choose <strong>Office</strong> ➪ Excel Options to display this dialog<br />

box.)<br />

Be very careful with the Set Precision As Displayed option. This option also affects normal values<br />

(nonformulas) that have been entered into cells. For example, if a cell contains the value<br />

4.68 and is displayed with no decimal places (that is, 5), checking the Precision As Displayed check box converts<br />

4.68 to 5.00. This change is permanent, and you can’t restore the original value if you later uncheck the<br />

Set Precision As Displayed check box. A better approach is to use Excel’s ROUND function to round off the<br />

values to the desired number of decimal places.<br />

CAUTION<br />

Floating point number errors<br />

Computers, by their very nature, don’t have infinite precision. Excel stores numbers in binary format by<br />

using eight bytes, which can handle numbers with 15-digit accuracy. Some numbers can’t be expressed precisely<br />

by using eight bytes, so the number stores as an approximation.<br />

To demonstrate how this lack of precision may cause problems, enter the following formula into cell A1:<br />

=(5.1-5.2)+1<br />

The result should be 0.9. However, if you format the cell to display 15 decimal places, you discover that<br />

Excel calculates the formula with a result of 0.899999999999999. This result occurs because the operation<br />

in parentheses is performed first, and this intermediate result stores in binary format by using an approximation.<br />

The formula then adds 1 to this value, and the approximation error is propagated to the final result.<br />

In many cases, this type of error doesn’t present a problem. However, if you need to test the result of that<br />

formula by using a logical operator, it may present a problem. For example, the following formula (which<br />

assumes that the previous formula is in cell A1) returns False:<br />

=A1=.9<br />

One solution to this type of error is to use Excel’s ROUND function. The following formula, for example,<br />

returns True because the comparison is made by using the value in A1 rounded to one decimal place.<br />

=ROUND(A1,1)=0.9<br />

Here’s another example of a “precision” problem. Try entering the following formula:<br />

=(1.333-1.233)-(1.334-1.234)<br />

This formula should return 0, but it actually returns –2.220446E-16 (a number very close to zero).<br />

If that formula is in cell A1, the following formula returns Not Zero.<br />

=IF(A1=0,”Zero”,”Not Zero”)<br />

One way to handle these “very close to zero” rounding errors is to use a formula like this:<br />

=IF(ABS(A1)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!