Re: math error or rounding problem Money type

Поиск
Список
Период
Сортировка
От Mark Kirkwood
Тема Re: math error or rounding problem Money type
Дата
Msg-id 484B224E.4080806@paradise.net.nz
обсуждение исходный текст
Ответ на Re: math error or rounding problem Money type  (Justin <justin@emproshunts.com>)
Ответы Re: math error or rounding problem Money type
Список pgsql-hackers
Justin wrote:
> 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. 
>

IFAIK (dimly recalling numerical analysis courses at university) SUM and 
ROUND can *never* be commuted. In general the recommended approach is to 
round as late as possible and as few times are possible - so your 1st 
query is the correct or best way to go.

Cheers

Mark


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Justin
Дата:
Сообщение: Re: math error or rounding problem Money type
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: [PATCHES] TRUNCATE TABLE with IDENTITY