Re: How useful is the money datatype?

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>
Cc: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>, Thom Brown <thombrown(at)gmail(dot)com>, PGSQL Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: How useful is the money datatype?
Date: 2009-10-03 16:05:39
Message-ID: 407d949e0910030905o67a45d78n4ddf0d8d07bd6bdd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/10/3 Grzegorz Jaśkiewicz <gryzman(at)gmail(dot)com>:
> depending on the countries, etc - keep currencies in 10.4 , or you can
> compromise to 10.3 , otherwise you might run into problems with rounding,
> etc.

Keeping more digits of precision than the application actually can use
is more likely to *cause* problems with rounding than solve them.

For example, if you calculate interest on a balance (using floating
point arithmetic) and then round it to $10.001 and store that in the
balance your application will tell the user and your accounting
department that they have $10 and their account. But if you do this
ten times they'll mysteriously have an extra cent that the accounting
department will not be able to account for.

To avoid problems like this you must store precisely as many digits as
the application requires. No more and no less. Intermediate
calculations can be done with more precision or floating point
arithmetic but you have to round or truncate before reporting the
results and then store precisely the value you reported.

--
greg

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martin Gainty 2009-10-03 16:14:19 Re: Procedure for feature requests?
Previous Message Merlin Moncure 2009-10-03 15:49:50 Re: How useful is the money datatype?