Re: How useful is the money datatype?

Поиск
Список
Период
Сортировка
От justin
Тема Re: How useful is the money datatype?
Дата
Msg-id 4AC921DC.1070102@emproshunts.com
обсуждение исходный текст
Ответ на Re: How useful is the money datatype?  (Rich Shepard <rshepard@appl-ecosys.com>)
Список 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


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

Предыдущее
От: Gerhard Wiesinger
Дата:
Сообщение: Re: Limit of bgwriter_lru_maxpages of max. 1000?
Следующее
От: Tim Landscheidt
Дата:
Сообщение: Re: Procedure for feature requests?