How to correct rounding errors in floating-point arithmetic (214118)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Excel 2002
- Microsoft Office Excel 2003
This article was previously published under Q214118 SYMPTOMS Many combinations of arithmetic operations on
floating-point numbers in Microsoft Excel and Microsoft Works may produce
results that appear to be incorrect by very small amounts. For example, the
equation may be evaluated to the quantity (-2.78E-17), or
-0.0000000000000000278 instead of 0. CAUSE This behavior is not a problem in or a limitation of Excel
or Works; this behavior occurs because the Institute of Electrical and
Electronics Engineers (IEEE) 754 floating-point standard requires that numbers
be stored in binary format. WORKAROUNDMethod 1To minimize any effects of floating point arithmetic storage
inaccuracy, use the Round() function to round numbers to the
number of decimal places that is required by your calculation. For example, if
you are working with currency, you would likely round to 2 decimal
places: =ROUND(1*(0.5-0.4-0.1),2) Method 2You can frequently prevent floating point rounding errors from
affecting your work by using the Precision as displayed
option. This option forces the value of each number in the worksheet to be the
precision that is displayed on the worksheet. Note Use of the Precision as Displayed option can
have cumulative calculation effects that can make your data increasingly
inaccurate over time. Use this option only if you are certain that the
displayed percision will maintain the accuracy of your data. To use
the Precision as displayed option, follow these steps:
- On the Tools menu, click
Options.
- On the Calculation tab, under
Workbook options, click to select the Precision as
displayed check box.
- Click OK.
If you use the Precision as displayed option,
you must format your numbers by using a specific number format. To
format cells to a specific number precision, follow these steps:
- Select the cells that you want to format.
- On the Format menu, click
Cells.
- On the Number tab, under
Category, click Number.
- In the Decimal places box, select the
precision (number of decimal places) that you want.
- Click OK.
REFERENCES For
additional information, click the following article number to view the article
in the Microsoft Knowledge Base: 78113
XL: Floating-point arithmetic may give inaccurate results
Excel 2002 and Excel 2003 For more information about changing the precision of
calculation, click Microsoft Excel Help on the
Help menu, type change when and how formulas are
calculated in the Office Assistant or the Answer Wizard, and then
click Search to view the topic.
Excel 2000 For more information about changing the
precision of calculation, click Microsoft Excel Help on the
Help menu, type change the way Microsoft Excel
calculates formulas in the Office Assistant or the Answer Wizard,
and then click Search to view the topic.
Modification Type: | Minor | Last Reviewed: | 3/16/2006 |
---|
Keywords: | kbprb KB214118 |
---|
|