avatar

ShinChven's Blog

Store Float in MySQL

Mon Jan 16 2023

Storing a float number in MySQL, you must specify the column's precision and scale.

CREATE TABLE `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `value` decimal(10,2) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
  • 10: is the precision, which is the total number of digits.
  • 2: is the scale, which is the number of digits after the decimal point.

Reference