Take the 2-minute tour ×

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

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

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 Currency

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.

share|improve this answer
Yeah. i think this will work. I doubt anyone even has that much money in this game! But i do wish MySQL would add a money type. –  Keverw Mar 10 '11 at 10:24
add comment

You should ask yourself "What is the most amount of money someone will have using my program?" and "To what precision do I require my decimal places?"

If you only need to handle up to a billion, then it seems (10,2) would be sufficient. If you wanted more precision for interest calculations perhaps you want (10,5). If you're just keeping track of a payroll and annual salary, it seems (7,2) would be sufficient (and I'd like to be in the 7 part, thanks!)

Without knowing the purpose of your data, it's hard to answer this. All I can give you is the questions you have to ask yourself.

share|improve this answer
add comment

If you are storing money in a database, you can use the int type but store in the minimal value (cent for dollars), then just divide by 100 when needed. It will work faster.

share|improve this answer
add comment

Your Answer


