If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SUM function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-26-04, 09:32
kristjangudni kristjangudni is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
SUM function

I need someone to explain to me how the SUMfunction works. Sounds stupid and maybe it is but I have a problem with this function. The problem is like this:

My table has a REAL column have two values. They are 968.9 and 927.9. When I do a select with SUM (select sum(ps) form ...) then DB2 returns 1896.800048828125. How come it returns with all these decimal numbers. I expect only to get 1896.8 and nothing more. I know that SUM returns double and I do something like "select decimal(sum(ps),10,2)..." but still I would like to know the answer to those unexpted precision.

Many thanks for wonderful forum.
Reply With Quote
  #2 (permalink)  
Old 10-26-04, 11:31
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by kristjangudni
I need someone to explain to me how the SUMfunction works. Sounds stupid and maybe it is but I have a problem with this function. The problem is like this:

My table has a REAL column have two values. They are 968.9 and 927.9. When I do a select with SUM (select sum(ps) form ...) then DB2 returns 1896.800048828125. How come it returns with all these decimal numbers. I expect only to get 1896.8 and nothing more. I know that SUM returns double and I do something like "select decimal(sum(ps),10,2)..."
The SUM function works exactly as it should with floating point numbers.

Floating point representation (that is, REAL or DOUBLE) of a number is inaccurate by definition. If you need more predictable results use DECIMAL.

You don't write software for a financial institution, do you? I should think about keeping my money under my mattress

:-)
Reply With Quote
  #3 (permalink)  
Old 10-27-04, 05:49
kristjangudni kristjangudni is offline
Registered User
 
Join Date: Sep 2004
Posts: 4
Yes I know that floating point numbers are inaccurate but I also know that other databases can implement SUM of float numbers (like in my example) without adding extra decimals.
Reply With Quote
  #4 (permalink)  
Old 10-27-04, 09:44
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by kristjangudni
Yes I know that floating point numbers are inaccurate but I also know that other databases can implement SUM of float numbers (like in my example) without adding extra decimals.
So, do these "other databases" have infinite floating point precision then? Or may be "they" are truncating or rounding off values to their liking? In either case they aren't IEEE754-compliant.

What are those "other databases" anyway?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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