MySQL小数类型超出范围错误 [英] MySQL Decimal Type Out Of Range Error

查看:190
本文介绍了MySQL小数类型超出范围错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码:

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

https://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小数类型超出范围错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆