Search Postgresql Archives

Re: How useful is the money datatype?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





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


--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux