# Thread: SUM function

1. Registered User
Join Date
Sep 2004
Posts
4

## Unanswered: 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.

2. :-)
Join Date
Jun 2003
Location
Toronto, Canada
Posts
5,516
Provided Answers: 1
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

:-)

3. 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.

4. :-)
Join Date
Jun 2003
Location
Toronto, Canada
Posts
5,516
Provided Answers: 1
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?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•