Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Rounding Numbers

Often when carrying out simple multiplication and addition between two
cells with numeric values, I must ROUND my answer to get a whole
number, like 0.

E.G. 4 - 4 = 0.0000000000454564543 or something like that. Why do
these inconsistencies happen? How can I avoid them.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Rounding Numbers

"nikita" wrote:
Why do these inconsistencies happen? How can I avoid them.


Answering the second question first.... You already do the correct thing to
avoid them, namely: the prolific, but prudent use of the ROUND() function.

The operative word is "prudent". Sometimes it is preferable to retain the
exact value of a computation in the cell and to round only selective
references to the cell.

Another alternative might be setting the "Precision as displayed"
calculation option (Tools Options Calculation in Excel 2003). But I
deprecate the use of PAD for a number of reasons. For one thing, it is not
selective; it applies to all cells that are not formatted as General.

Caveat: If you choose to experiment with PAD, be sure to copy the Excel
file first. Setting PAD can have some irreversible pervasive effects.


As to the first question.... For a detailed explanation, take a look at
http://support.microsoft.com/kb/78113 .

In a nutshell: most numbers with decimal fractions cannot be represented
exactly as displayed because of the internal format used by Excel and most
applications. This causes "numerical aberrations" to arise in most
arithmetic operations. (I try to avoid the phrase "numerical error" because
this is not a defect.)

For example, try =IF(10.1 - 10 = 0.1, TRUE). It returns FALSE (!).

The constant 10.1 has a different approximation of 0.1 than the constant 0.1
itself. When we subtract 10 from 10.1, we are left with the different
approximation.

In this case, the difference is big enough that Excel does not consider them
equal. But in other cases and in some contexts, Excel has a half-baked
algorithm that tries to hide the difference.


----- original message ------

"nikita" wrote in message
...
Often when carrying out simple multiplication and addition between two
cells with numeric values, I must ROUND my answer to get a whole
number, like 0.

E.G. 4 - 4 = 0.0000000000454564543 or something like that. Why do
these inconsistencies happen? How can I avoid them.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,059
Default Rounding Numbers

PS....

Since you used the term ROUND (all caps), I assumed you are asking about
Excel.

But since m.p.e.programming is usually used for VBA questions, I should
add....


I wrote:
For example, try =IF(10.1 - 10 = 0.1, TRUE).
It returns FALSE (!).


Similarly, in VB:

Msgbox 10.1 - 10 = 0.1

displays FALSE.

Caveat: If you are using VBA, I would use WorksheetFunction.Round, not the
VB Round() function. They behave differently with some values. The VB
Round() function does "banker's rounding". For example, compare Round(0.5)
and Round(1.5) with WorksheetFunction.Round(0.5,0) and
WorksheetFunction.Round(1.5,0)


----- original message -----

"JoeU2004" wrote in message
...
"nikita" wrote:
Why do these inconsistencies happen? How can I avoid them.


Answering the second question first.... You already do the correct thing
to avoid them, namely: the prolific, but prudent use of the ROUND()
function.

The operative word is "prudent". Sometimes it is preferable to retain the
exact value of a computation in the cell and to round only selective
references to the cell.

Another alternative might be setting the "Precision as displayed"
calculation option (Tools Options Calculation in Excel 2003). But I
deprecate the use of PAD for a number of reasons. For one thing, it is
not selective; it applies to all cells that are not formatted as General.

Caveat: If you choose to experiment with PAD, be sure to copy the Excel
file first. Setting PAD can have some irreversible pervasive effects.


As to the first question.... For a detailed explanation, take a look at
http://support.microsoft.com/kb/78113 .

In a nutshell: most numbers with decimal fractions cannot be represented
exactly as displayed because of the internal format used by Excel and most
applications. This causes "numerical aberrations" to arise in most
arithmetic operations. (I try to avoid the phrase "numerical error"
because this is not a defect.)

For example, try =IF(10.1 - 10 = 0.1, TRUE). It returns FALSE (!).

The constant 10.1 has a different approximation of 0.1 than the constant
0.1 itself. When we subtract 10 from 10.1, we are left with the different
approximation.

In this case, the difference is big enough that Excel does not consider
them equal. But in other cases and in some contexts, Excel has a
half-baked algorithm that tries to hide the difference.


----- original message ------

"nikita" wrote in message
...
Often when carrying out simple multiplication and addition between two
cells with numeric values, I must ROUND my answer to get a whole
number, like 0.

E.G. 4 - 4 = 0.0000000000454564543 or something like that. Why do
these inconsistencies happen? How can I avoid them.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ROUNDING NUMBERS JOHN New Users to Excel 3 February 27th 09 09:27 PM
Rounding numbers time conversion[_2_] Excel Discussion (Misc queries) 5 August 8th 08 03:38 PM
Rounding Numbers j41cam Excel Discussion (Misc queries) 1 April 18th 05 07:47 PM
I need help rounding numbers, please. Wind54Surfer Excel Discussion (Misc queries) 5 February 21st 05 07:15 PM
Rounding numbers then doing a sum of those numbers produces incorrect result. GzusRox Excel Programming 2 July 26th 03 01:42 PM


All times are GMT +1. The time now is 10:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"