Storing currency values in MySQL database Storing currency values in MySQL database mysql mysql

Storing currency values in MySQL database


Financial data can be stored as DECIMAL(p,s) where p is the number of significant digits, and s is the scale (number of places to the right of the decimal point). See The MySQL documentation.

Also from O'Reilly's High Performance MySQL, chapter 3:

"...you should use DECIMAL only when you need exact results for fractional numbers--for example, when storing financial data."

From O'Reilly's Learning MySQL:

DECIMAL is, "...A commonly used numeric type. Stores a fixed-point number such as a salary or distance..."

And MySQL Pocket Reference:

DECIMAL "...Stores floating-point numbers where precision is critical, such as for monetary values."


There is nothing wrong with the approach you describe. There is no right or wrong when it comes to this question.

You have to keep in mind that to display a $ value to the user, you would need to always do a division operation or some kind of formatting.

Will it be easier to debug your formulas/calculations if everything was in cents or dollars? Will you be displaying the values in cents or dollars? etc.

Keep it simple, but either way you'll have to use a decimal.