'currency' question; precision/decimal meaing

Started by Will Fitzgeraldover 25 years ago5 messagesgeneral
Jump to latest
#1Will Fitzgerald
fitzgerald@inetmi.com

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?

#2Igor Roboul
igor@raduga.dyndns.org
In reply to: Will Fitzgerald (#1)
Re: 'currency' question; precision/decimal meaing

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

In reply to: Will Fitzgerald (#1)
Re: 'currency' question; precision/decimal meaing

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 ...

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: hubert depesz lubaczewski (#3)
Re: '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)?

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

#5Jan Wieck
JanWieck@Yahoo.com
In reply to: hubert depesz lubaczewski (#3)
Re: 'currency' question; precision/decimal meaing

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 #