Page 1 of 1
need suggestion: fields for money
Posted: Wed Jul 27, 2005 11:08 am
by php12342005
waht kind of fields do you use for currencies (money)?
i.e. a good may be sold in different currencies,
i.e. $100.10 US dollars or $60.32 EU dollars,
how do you describe the situation?
I prepare to use:
(field 1) DOUBLE for amount of money (i.e. 100.10)
(field 2) CHAR(20) for type of money (i.e. US)
but I feel this way is not good, please give suggestions.
thanks
Posted: Wed Jul 27, 2005 11:09 am
by nielsene
Look into NUMERIC instead of Double, but otherwise I'd do what you show. one field for amount, one field for currency. If your using InnoDB in MySQL or another DB with referential integrity, I'd make the currency column a foreign key to a list of currencies to catch mistakes.
Posted: Wed Jul 27, 2005 11:23 am
by php12342005
good suggestion,
thanks.
NUMERIC(M,B) - I guess M is bytes, what does B mean?
a foreign key to a list of currencies to catch mistakes
I will do it also.
Posted: Wed Jul 27, 2005 11:29 am
by nielsene
M is digits, B is number of decimal points so
NUMERIC(10) would be an integer with up ten digits + sign.
NUMERIC(10,2) wuld have two decimal place digits and 8 non-decimal place digits.
If you're dealing with prices often NUMERIC(XXX,2) is good where you've chosen an appopriate XXX, then adding 1 or 2 just in case.
If you're dealing more with exchange rates and finanncial matters, you typically need to use 3 decimal places (or more) depending on local laws.
Posted: Wed Jul 27, 2005 2:00 pm
by timvw
I know € euro forces you to use 4 decimals

Currency
Posted: Mon Aug 01, 2005 7:13 am
by AnarKy
Perhaps you could store all amount in one currency type (e.g US Dollar)
Then you could use conversions to convert the amount from US Dollars to
the local currency based on the exchange rates...
(which you may need to update or get from an external source.)
Posted: Mon Aug 01, 2005 7:26 am
by timvw
But if i have money in euro... i don't want to see i suddenly have less euros because dollar rates changed
Having a (currency, amount) setup seems more appropriate
