MySQL decimal type error out of range

This code:

DROP DATABASE IF EXISTS `my_db`;
CREATE DATABASE `my_db`; 
CREATE TABLE `my_db`.`my_table` (
    `id` integer NOT NULL AUTO_INCREMENT, 
    `multiplier` decimal(18, 10) NOT NULL, 
    PRIMARY KEY (`id`)
) Engine=InnoDB;

INSERT INTO `my_db`.`my_table` (`multiplier`) VALUES (100000000.0);

It returns an error:

Error Code: 1264. Out of range value for column 'multiplier' at row 1

Why? There are only 9 digits before the comma, while the column should work up to 18 digits - or am I missing something? Thanks.

+4
source share
1 answer

decimal(18, 10) means 10 digits after decimal and 8 to decimal, not up to 18 digits

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

For example, the DECIMAL column (18.9) has nine digits on either side of the decimal point, so the integer part and fractional part each require 4 bytes. The DECIMAL column (20.6) has fourteen integer digits and six fractional digits. Integer digits require four bytes for nine digits and 3 bytes for the remaining five digits. Six fractional digits require 3 bytes.

+9

Source: https://habr.com/ru/post/1613213/


All Articles