Deversus Software Inc.

The Proper Way to Store Currency/Money in mySQL

by Mike Polga on January 7, 2011

When storing currency (or any decimal number for that matter) in mySQL, it’s extremely important to be aware of the differences in the decimal place storage methods available. Doubles and Floats are imprecise storage methods (as they use floating point arithmetic), and can lead to major problems when representing currency, as the cents value is obviously important. Thus, always use the decimal type for currency or money storage in mySQL! In most cases, 10 digits before the decimal place and 2 digits after should be sufficient, as shown in the screenshot of phpMyAdmin below.

currency mySQL column of the decimal data type

phpMyAdmin screenshot showing how to properly store currency/money in mySQL

Leave a Comment

 

Previous post:

Next post: