Best data type to store money values in MySQL

currency, mysql, sqldatatypes

Solution

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

See MySQL Numeric Types:

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

Problem

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)?

Original source

Related problems