Re: How useful is the money datatype?

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: How useful is the money datatype?
Дата
Msg-id 407d949e0910030905o67a45d78n4ddf0d8d07bd6bdd@mail.gmail.com
обсуждение исходный текст
Ответ на Re: How useful is the money datatype?  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: How useful is the money datatype?
Следующее
От: Martin Gainty
Дата:
Сообщение: Re: Procedure for feature requests?