Re: How useful is the money datatype? - Mailing list pgsql-general

From Greg Stark
Subject Re: How useful is the money datatype?
Date
Msg-id 407d949e0910030905o67a45d78n4ddf0d8d07bd6bdd@mail.gmail.com
Whole thread Raw
In response to Re: How useful is the money datatype?  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
List pgsql-general
2009/10/3 Grzegorz Jaśkiewicz <gryzman@gmail.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

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: How useful is the money datatype?
Next
From: Martin Gainty
Date:
Subject: Re: Procedure for feature requests?