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);
Returns an error:
Error Code: 1264. Out of range value for column 'multiplier' at row 1
Why? There are only 9 digits before comma whereas the column should work until 18 digits - or am I missing something here? Thank you.
decimal(18, 10)
means 10 digits after decimal and 8 before decimal, not until 18 digits
https://dev.mysql.com/doc/refman/5.1/en/precision-math-decimal-characteristics.html
For example, a DECIMAL(18,9) column has nine digits on either side of the decimal point, so the integer part and the fractional part each require 4 bytes. A DECIMAL(20,6) column has fourteen integer digits and six fractional digits. The integer digits require four bytes for nine of the digits and 3 bytes for the remaining five digits. The six fractional digits require 3 bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With