Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Best way to store currency symbols?

Just wondering what the best way of storing currency values and symbols within a MySQL DB might be?

Thanks to browsing SO, I'm storing my amounts as a Decimal (19,2) value - which is fine - but am more concerned with the Currency symbol (e.g. €, £, $, etc.), as I want to allow the end user to set their own currency unit at the set up stage. I also want to avoid any uncertainty as regards, which are currently set at utf8 (both sides).

The way I have at the moment is to store them as HTML Numerical Codes using PHP ifelse statements to filter input. Is this the best method? If not, what is? Is there a need at all? Many thankee's in advance!

like image 532
Eamonn Avatar asked Jan 19 '23 01:01

Eamonn


1 Answers

imho, you can break the data into two columns

amount      = decimal(19,2) --- question : unsigned for positive value only
currency_id = int(10) unsigned --- which is ID to currency table

when the currency field is reference to another table,
you can storing all sort of additional info into that table (such as exchange rate)
to better describe how you want the symbol get presented

like image 153
ajreal Avatar answered Jan 21 '23 14:01

ajreal