Is it okay to store money as decimal(22,2) in MySQL?

Keverw picture Keverw · Mar 5, 2011 · Viewed 13.4k times · Source

Is it okay to store money values as decimal(22,2) in MySQL? I am writing a web based marketplace and Ad network for a virtual world.

Answer

Brandon Frohbieter picture Brandon Frohbieter · Mar 5, 2011

What if someone has sextillion dollars?!? The field couldn't contain this massive pile of benjamins....

In seriousness though, SQL Server and PostgreSQL have a money datatype, and Access has a currency datatype. Oracle and MySQL have neither.

This thread - Best data type for storing currency values in a MySQL database

however recommends 4 significant digits for some reason, I suppose in case you need fractional cents (stock shares, etc).

If no user could have over sextillion dollars (in seriousness), and you don't need to calculate fractions of cents for storage, your format should be just fine.