Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 723
Keverw Avatar asked Mar 05 '11 04:03

Keverw


1 Answers

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.

like image 109
Brandon Frohbieter Avatar answered Oct 10 '22 01:10

Brandon Frohbieter