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

From Sam Mason
Subject Re: How useful is the money datatype?
Date
Msg-id 20091003154023.GC5407@samason.me.uk
Whole thread Raw
In response to Re: How useful is the money datatype?  (Raymond O'Donnell <rod@iol.ie>)
Responses Re: How useful is the money datatype?
List pgsql-general
On Sat, Oct 03, 2009 at 12:20:57PM +0100, Raymond O'Donnell wrote:
> I thought the idea of NUMERIC was that the value was exact, avoiding
> rounding problems that you might get with other floating-point types?

Nope, sorry it's still a computer and thus can't represent anything
with infinite precision (just numeric fractions in PG's case, let alone
irrational numbers). For example:

  select (numeric '1'/3) * 3;

Gives me back 0.99999999999999999999.

What NUMERIC datatypes allow you to do however is allow you to specify
the precision used in calculations and storage (i.e. as 10 digits, four
of those being fractional digits, as above).  Thus you've got a chance
of putting a bound on the total error that can accumulate during a
calculation.

For example, you can choose between storing a few more digits in your
accounting tables so that when doing aggregations it comes out with the
"right" number at the end---i.e. 10 orders of something cost the same as
one order of 10 items.  Or you set the precision to be coarser and then
the values that have been rounded off will match everything else.

--
  Sam  http://samason.me.uk/

pgsql-general by date:

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