Re: Money data type in PostgreSQL?

Поиск
Список
Период
Сортировка
От Graham Leggett
Тема Re: Money data type in PostgreSQL?
Дата
Msg-id 3FCFA086.90300@sharp.fm
обсуждение исходный текст
Ответ на Re: Money data type in PostgreSQL?  (Christopher Browne <cbbrowne@acm.org>)
Ответы Re: Money data type in PostgreSQL?
Список pgsql-general
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.

YMMV.

Regards,
Graham
--


В списке pgsql-general по дате отправления:

Предыдущее
От: Alvar Freude
Дата:
Сообщение: Re: Making a tree with "millions and millions" of dynamic
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: query and pg_dump problem on my postgresql 6.5.3/Redhat 6.2