Re: math error or rounding problem Money type - Mailing list pgsql-hackers

From Merlin Moncure
Subject Re: math error or rounding problem Money type
Date
Msg-id b42b73150806110703m5e653c7fg1cbb88800b41309f@mail.gmail.com
Whole thread Raw
In response to Re: math error or rounding problem Money type  (Gregory Stark <stark@enterprisedb.com>)
List pgsql-hackers
On 6/8/08, Gregory Stark <stark@enterprisedb.com> wrote:
> I don't think "as late as possible" applies with money. If you were dealing
> with approximate measurements you want to round as late as possible because
> rounding is throwing away precision. But if you're dealing with money you're
> dealing with exact quantities.
>
> There is only going to be one correct time to round and that's whenever you're
> creating an actual ledger item or order line item or whatever. Once you've
> calculated how much interest to credit or whatever you have to make that
> credit an exact number of cents and the $0.004 you lost or gained in rounding
> never comes up again.

Completely correct.  In a proper accounting system you can only pull
from a very limited subset of arithmetic operations.  'rounding' is
not one of them except in the special case you mention above.

merlin


pgsql-hackers by date:

Previous
From: "billy"
Date:
Subject: why copy tuple in the end of trigger when nothing changed in NEW OLD record variable
Next
From: Zdenek Kotala
Date:
Subject: Proposal: Multiversion page api (inplace upgrade)