Best data type to store money values in MySQL

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


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.


    You can use DECIMAL or NUMERIC both are same

    The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data. In MySQL, NUMERIC is implemented as DECIMAL, so the following remarks about DECIMAL apply equally to NUMERIC. : MySQL

    ie DECIMAL(10,2)

    示例设置

    Good read


    It depends on your need.

    Using DECIMAL(10,2) usually is enough but if you need a little bit more precise values you can set DECIMAL(10,4) .

    If you work with big values replace 10 with 19 .

    链接地址: http://www.djcxy.com/p/25144.html

    上一篇: MySQL转换为TINYINT

    下一篇: 在MySQL中存储货币值的最佳数据类型