What is the best datatype to store 18 digit numeric value in MySQL

Viewed 391

What is the best data type to store 18 digit numeric value in MySQL

  • The number is always positive
  • This column will be a primary key and partition column
  • The number of precision is always 18
  • The number of decimals is always 0

There are multiple datatypes

BIGINT
FLOAT(18,0)
DECIMAL(18,0)
DOUBLE(18,0)

What is the industry standard and most efficient datatype in MySQL for storage and retrival of such values.

1 Answers

Use BIGINT UNSIGNED. It can support at least 19 digits of precision. The maximum value is 18446744073709551615.

There's no advantage to using DECIMAL, FLOAT, or DOUBLE in this case, because you say the values have no scale.

But you do need 18 digits of precision, so the rounding behavior of FLOAT/DOUBLE may not do what you need.

Related