此代码:
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);返回错误:
Error Code: 1264. Out of range value for column 'multiplier' at row 1为什么?逗号前只有9位数字,而该列应一直显示到18位数字-还是我在这里遗漏了什么?谢谢你.
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)表示小数点后10位,小数点前8位,直到18位
decimal(18, 10) means 10 digits after decimal and 8 before decimal, not until 18 digits
dev.mysql. com/doc/refman/5.1/en/precision-math-decimal-characteristics.html
例如,DECIMAL(18,9)列的两边有九位数字 小数点,因此整数部分和小数部分各 需要4个字节. DECIMAL(20,6)列具有14个整数 和六个小数位数.整数需要四个字节 9位数字,其余5位数字为3个字节. 6 小数位需要3个字节.
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.
更多推荐
MySQL小数类型超出范围错误
发布评论