Re: How useful is the money datatype?

From: justin <justin(at)emproshunts(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How useful is the money datatype?
Date: 2009-10-04 22:29:48
Message-ID: 4AC921DC.1070102@emproshunts.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rich Shepard wrote:
>
> In the early and mid-1980s we used a procedure for business
> applications
> involving money that worked regardless of programming language or
> platform.
> To each (float, real) monetary amount we added 0.005 and truncated the
> result
> to two digits on the right of the decimal point. In almost all cases,
> this
> allowed financial calculations to be correct to the nearest penny.
>
> Financial calculations are still imperfect. Now and then I see this in
> both my business and personal bank statements when reconciliation is
> off by
> a penny or two. The transaction amounts (debits and credits) match,
> but the
> bank comes out with a different total than do I. This is usually only
> for a
> month or two before we are once again in agreement.
>
> Rich
>
>
Rich what causes the difference you are referring to is method used to
round, bankers rounding aka (round to even) vs basic rounding we are
taught in school aka (round half up).
http://en.wikipedia.org/wiki/Rounding

General what i do is leave more digits in the number than is needed then
round after all the calculations are done... A common problem
applications/databases suffer from is inconsistent precision. In one
place the database is using 4 digits another 6 in another 0 and in
another 2 digits. Be consistent in the use of precision if not, be
prepared to untangle a nightmare.

The money type i have found is absolutely worthless when doing math but
using it to simplify formating great.

select 123456789::text::money;

set session lc_monetary to 'fr_FR.UTF-8';
select 123456789::text::money

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tim Landscheidt 2009-10-05 00:03:38 Re: Procedure for feature requests?
Previous Message Gerhard Wiesinger 2009-10-04 20:19:21 Re: Limit of bgwriter_lru_maxpages of max. 1000?