user198729
user198729

Reputation: 63676

What does M,D mean in decimal(M,D) exactly?

Does anyone know about this?

Upvotes: 15

Views: 21312

Answers (3)

Nate C-K
Nate C-K

Reputation: 5932

https://dev.mysql.com/doc/refman/5.7/en/precision-math-decimal-characteristics.html

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.1 are as follows:

  • M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL allowed a range of 1 to 254.)
  • D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

[Note: the link above has been updated to point to the MySQL 5.7 docs, but the text was quoted from the MySQL 5.1 docs.]

Upvotes: 8

Alex Martelli
Alex Martelli

Reputation: 882133

As the docs say:

M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL allowed a range of 1 to 254.)

D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

So M stands for Maximum (number of digits overall), D stands for Decimals (number of digits to the right of the decimal point).

Upvotes: 28

gimel
gimel

Reputation: 86422

The doc says:

The declaration syntax for a DECIMAL column remains DECIMAL(M,D), although the range of values for the arguments has changed somewhat:

  • M is the maximum number of digits (the precision). It has a range of 1 to 65. This introduces a possible incompatibility for older applications, because previous versions of MySQL allow a range of 1 to 254. (The precision of 65 digits actually applies as of MySQL 5.0.6. From 5.0.3 to 5.0.5, the precision is 64 digits.)

  • D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

Upvotes: 2

Related Questions