Re: How useful is the money datatype?
От | Craig Ringer |
---|---|
Тема | Re: How useful is the money datatype? |
Дата | |
Msg-id | 1255402983.4702.11.camel@wallace.localnet обсуждение исходный текст |
Ответ на | Re: How useful is the money datatype? (Sam Mason <sam@samason.me.uk>) |
Список | pgsql-general |
On Sun, 2009-10-04 at 17:12 +0100, Sam Mason wrote: > > There is an open source library by IBM that I use in my C++ code to do > > this, and may be it can be incorporated into PG > > > > it is called decNumber > > http://speleotrove.com/decimal/decnumber.html > > How would this help over PG's existing numeric type? I don't see it either. Pg's NUMERIC type is quite suitable for mixing large and small values in calculations with reasonable precision. test=> SELECT NUMERIC '100000000' * NUMERIC '0.00000000009'; 0.00900000000 test=> SELECT NUMERIC '10000090009.000000000000000001' / NUMERIC '0.0000000000000000000000002'; 50000450045000000000000000005000000.0000000000000000000000000 Sometimes you have to be very careful to make sure that Pg interprets operands as NUMERIC, though, rather than as floats. I've been extremely happy with the NUMERIC data type when working with monetary values. For scientific use I wish there was an equivalent type with explicit accumulation of error so I knew how much of the value was valid, but you don't need that for financial calculations. -- Craig Ringer
В списке pgsql-general по дате отправления: