View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Sum show difference of -0.000000000002501104298755

Often, programs do not test for perfect equality due to the
limitations of floating point representations. Instead, a difference
less than some very small value is considered equal. E.g.,

Const MIN_NUM As Double = 0.00000000000001
Dim A As Double
Dim B As Double

' A = some calculation
' B = some other calculation

If A = B Then
' might have floating point problems
End If
' instead use
If Abs(A - B) < MIN_NUM Then
' close enough to be considered equal
End If

Some languages (e.g, C/C++) have the MIN_NUM value defined as part of
the standard package for just this sort of thing.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Fri, 12 Dec 2008 16:19:47 -0600, "Fred Smith"
wrote:

Chip's explanation applies, Chuck. You're adding in decimal, but computers
add in binary. Conversions from decimal to binary are imperfect, especially
in decimal positions 13 to 24. If you want the sum to be exactly zero, you
need to round your numbers.

Regards,
Fred.

"Chuck" wrote in message
...
Thank You Sheeloo. I read the article but am not sure it applies to this
issue.
When I expand the decimal places on the column to 30, there are only 0's
after the second decimal place for each cell in the sum. But the sum has
values other than 0 starting in decimal position 13 thru 24, then all 0s
to
position 30. I would thing there would need to be some value besides 0 in
position 25 thru 30?

"Sheeloo" wrote:

See http://www.cpearson.com/excel/rounding.htm for an excellent article
on
the subject...

"Chuck" wrote:

The spreadsheet was created from an Access query where the column is
defined
as double with 2 decimil places.
In Excel I expand the column to 30 decimal places and none of the
values
have anything but 0 past the second decimal place.
Yet when I =SUM(E1:E763) I get the total
of -0.000000000002501104298755.
I have tried changing the format in Excel to currency, general,
accounting,
no change?
Any ideas would be appreciated.