MySQL:小数数据类型的大小 [英] MySQL: Size of decimal data type
问题描述
我有一些来自服务器的值需要存储在我的数据库中.我不是MySQL专家,但对于基本的输入/输出我了解得足够多.现在,我正在尝试确定存储以下小数点时应使用的长度.
tax_rate [DECIMAL ?,?]: value(0.014840000000)
units [DECIMAL ?,?]: value(1.00)
initial_charge [DECIMAL ?,?]: value(2.5110)
charge [DECIMAL ?,?]: value(2.8967)
link_tax [DECIMAL ?,?]: value(0.385652)
exempt [DECIMAL ?,?]: value(0.0000)
tax [DECIMAL ?,?]: value(0.042986)
base_price [DECIMAL ?,?]: value(41.8500)
我希望有人可以建议我为这些值使用正确的大小,因为WELL解释了他们为什么选择这些值.或者也许链接到一篇文章,该文章深入解释了MySQL的小数.
任何帮助将不胜感激.
谢谢!
------- 编辑 --------
在阅读MySQL文档之后,有一个很好的解释来确定十进制类型的大小.这些是我为用例设置的大小:
tax_rate [DECIMAL 15,12]: value(0.014840000000) ? max(999.999999999999)
units [DECIMAL 6,2]: value(1.00) ? max(9999.99)
initial_charge [DECIMAL 9,4]: value(2.5110) ? max(99999.9999)
charge [DECIMAL 9,4]: value(2.8967) ? max(99999.9999)
link_tax [DECIMAL 9,6]: value(0.385652) ? max(999.999999)
exempt [DECIMAL 9,4]: value(0.0000) ? max(9999.9999)
tax [DECIMAL 10,6]: value(0.042986) ? max(999999.999999)
base_price [DECIMAL 10,4]: value(41.8500) ? max(999999.9999)
来自 解决方案
From MySQL:
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.1 are as follows:
M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL permitted a range of 1 to 254.)
D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.
Consider this number: 123456789.12345 here M
is 14
and D
is 5
then based on this principle you can set DECIMALS(M,D) for each column based on Their expected maximum values.
这篇关于MySQL:小数数据类型的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!