MySQL – Best Data Type to Store Money Values

currencymysqlsqldatatypes

I want to store many records in a MySQL database. All of them contains money values. But I don't know how many digits will be inserted for each one.
Which data type do I have to use for this purpose?
VARCHAR or INT (or other numeric data types)?

Best Answer

Since money needs an exact representation don't use data types that are only approximate like float. You can use a fixed-point numeric data type for that like

decimal(15,2)
  • 15 is the precision (total length of value including decimal places)
  • 2 is the number of digits after decimal point
  • The max possible number in this example would be 9999999999999.99

See MySQL Numeric Types:

These types are used when it is important to preserve exact precision, for example with monetary data.