MySQL小数类型超出范围错误

编程入门 行业动态 更新时间:2024-10-07 22:18:52
本文介绍了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

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小数类型超出范围错误

本文发布于:2023-10-23 02:26:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519470.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小数   错误   类型   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!