MySQL DECIMAL 数据类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12664735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:02:54  来源:igfitidea点击:

MySQL DECIMAL data type

mysql

提问by dbj44

I have a column in MySQL with the type DECIMAL(2,1). When I insert the number 10 into the database it reads 9.9. I want it to read 10.0. Any ideas? Thanks.

我在 MySQL 中有一个类型为 DECIMAL(2,1) 的列。当我将数字 10 插入数据库时​​,它显示为 9.9。我希望它读取 10.0.0。有任何想法吗?谢谢。

回答by Bart Friederichs

DECIMAL(2,1)means (as the manualsuggests) a decimal of 2 characters wide (in total!) and 1 decimal. If you want 10.0, you need DECIMAL(3,1)(three wide, one decimal).

DECIMAL(2,1)意味着(如手册所建议的)2 个字符宽(总共!)和 1 个小数的小数。如果你想要10.0,你需要DECIMAL(3,1)(三个宽,一个小数)。