Thread: 'currency' question; precision/decimal meaing
I want to store prices in a table. What's the best way to do this (since 'money' is deprecated)? What do 'precision' and 'decimal' mean for the numeric type?
On Fri, Nov 10, 2000 at 01:13:23PM -0500, Will Fitzgerald wrote: > I want to store prices in a table. What's the best way to do this (since > 'money' is deprecated)? I use integer type, and assume that last two digits are cents (really kopeiki :-) ) -- Igor Roboul, Unix System Administrator & Programmer @ sanatorium "Raduga", Sochi, Russia http://www.brainbench.com/transcript.jsp?pid=304744
On Fri, Nov 10, 2000 at 01:13:23PM -0500, Will Fitzgerald wrote: > I want to store prices in a table. What's the best way to do this (since > 'money' is deprecated)? use int4 (or int8) and assume that the value is multipied by 100 (or another value - depends on your local currency. for example: $400 i will store as 40000 $2.34 i will store as 234 this is much better, and safer than useing floating point fields. depesz -- hubert depesz lubaczewski ------------------------------------------------------------------------ najwspanialszą rzeczą jaką dało nam nowoczesne społeczeństwo, jest niesamowita wręcz łatwość unikania kontaktów z nim ...
>> I want to store prices in a table. What's the best way to do this (since >> 'money' is deprecated)? Use type numeric, eg, numeric(12,2) if you want up to 12 digits total with 2 of 'em after the decimal point (xxxxxxxxxx.xx). regards, tom lane
hubert depesz lubaczewski wrote: [Charset iso-8859-2 unsupported, filtering to ASCII...] > On Fri, Nov 10, 2000 at 01:13:23PM -0500, Will Fitzgerald wrote: > > I want to store prices in a table. What's the best way to do this (since > > 'money' is deprecated)? > > use int4 (or int8) and assume that the value is multipied by 100 (or another > value - depends on your local currency. > for example: > $400 > i will store as > 40000 > $2.34 > i will store as > 234 > > this is much better, and safer than useing floating point fields. NUMERIC is arbitrary precision, allows all kinds of computation and the internal storage and handling is OK for bookkeeping purposes according to german law (which doesn't allow floating point because of possible rounding). NUMERIC is the choice for amounts of money. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #