Re: Money data type in PostgreSQL?

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Graham Leggett <minfrin(at)sharp(dot)fm>
Cc: Christopher Browne <cbbrowne(at)acm(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Money data type in PostgreSQL?
Date: 2003-12-04 23:40:57
Message-ID: 3FCFC609.1000503@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Graham Leggett wrote:

> Christopher Browne wrote:
>
>> But to get the pennies right on a $10,000 USD transaction converted
>> into GBP (UK Pounds), you need all the official precision that there
>> is. And if your calculation is off by 4 cents, some of those
>> accounting folk are liable to thrash you mercilessly over it. If you
>> get calculations WRONG, they get really uncomfortable, and want to
>> know why.
>
> What I have done is store the currency amounts as bigints, at the same
> precision defined for the currency (ie cents for dollars, pence for
> pounds, etc). This guarantees that you don't get any rounding errors
> when storing the figures as a floating point type. When manipulating the
> numbers, I use Java BigDecimals, which don't lose any precision either,
> and convert back to bigints to store in the database.

You won't get any rounding errors in NUMERIC either. What people should
be concerned of is to find an arbitrary precision package for the
frontend programming language they're using.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2003-12-04 23:45:55 Re: are cursors necessary?
Previous Message Richard Huxton 2003-12-04 23:31:18 Re: are cursors necessary?