Re: math error or rounding problem Money type

From: Justin <justin(at)emproshunts(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: math error or rounding problem Money type
Date: 2008-06-07 22:38:54
Message-ID: 484B0DFE.2050101@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Justin <justin(at)emproshunts(dot)com> writes:
>
>> I believe i have found a math bug/rounding problem with Money type when
>> its used with SUM()... Postgresql 8.3.1
>>
>
> You do know that money only stores two fractional digits?
>
> regards, tom lane
>
yes. The question is why are the to sides not equal anymore

Take this

Select
'2',
round(sum( beginBalance ),6) as beginbalance,
round(sum( negative ),6) as debit,
round(sum( positive ),6) as credit,
round(sum( difference ),6) as difference,
round(sum( endbalance),6) as endbalance
from trailbalance
union
Select
'1',
sum( round(beginBalance,6)) as beginbalance,
sum( round(negative,6)) as debit,
sum( round(positive,6)) as credit,
sum( round(difference,6)) as difference,
sum( round(endbalance,6)) as endbalance
from trailbalance

"1" -0.000006 -11250546.743752 11250546.743752 0.000000 -0.000007
"2" 0.000000 -11250546.743752 11250546.743752 0.000000 0.000000

At the very least this show a clear warning when rounding do it after
all the sum function is called not before.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Kirkwood 2008-06-08 00:05:34 Re: math error or rounding problem Money type
Previous Message Tom Lane 2008-06-07 22:26:54 Re: math error or rounding problem Money type