php - MySQL:十进制数据类型的大小

标签 php mysql

我有一些来自服务器的值需要存储在我的数据库中。我不是 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)

我希望有人可以建议我需要为这些值使用的正确大小,同时解释他们选择这些值的原因。或者链接到一篇深入解释 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)

最佳答案

来自 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.

考虑这个数字:123456789.12345 这里 M14D5 那么根据这个原则你可以根据每列的预期最大值为每列设置 DECIMALS(M,D)。

关于php - MySQL:十进制数据类型的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201266/

相关文章:

mysql - Hibernate QuerySyntaxException,表未映射

Mysql重复外键约束

MySQL workbench 不显示表

php - foreach用于绘制一个html表格

php - MySQL数据抓取方式

php - Mysql 获取具有特定顺序的日期之间的唯一记录

php - SQL - 连接两个表

mysql - Flash - 最快的 MySQL 连接

php - 用于验证 ip-list 中的 ip-range 的正则表达式

php - Mysql用户与自身比较