存储统计数据,我需要 DECIMAL、FLOAT 还是 DOUBLE?
我创作是为了好玩,但我仍然想认真对待它,这是一个托管各种测试的网站.我希望通过这些测试收集统计数据.
I am creating for fun, but I still want to approach it seriously, a site which hosts various tests. With these tests I hope to collect statistical data.
一些数据将包括测试完成时间的百分比.我可以轻松计算测试的百分比,但我希望返回真实数据,因为我存储了有关完成测试的各种不同值.
Some of the data will include the percentage of the completeness of the tests as they are timed. I can easily compute the percentage of the tests but I would like true data to be returned as I store the various different values concerning the tests on completion.
大多数值都是 PHP 浮点数,所以我的问题是,如果我想要真正的统计数据,我应该将它们存储在 MYSQL 中作为 FLOAT、DOUBLE 还是 DECIMAL.
Most of the values are, in PHP floats, so my question is, if I want true statistical data should I store them in MYSQL as FLOAT, DOUBLE or DECIMAL.
我想使用 MYSQL 的函数,例如 AVG()
和 LOG10()
以及 TRUNCATE()
.为了让 MYSQL 根据我插入的值返回真实数据,我应该使用什么作为数据库列选择.
I would like to utilize MYSQL'S functions such as AVG()
and LOG10()
as well as TRUNCATE()
. For MYSQL to return true data based off of my values that I insert, what should I use as the database column choice.
我问是因为有些数字可能是也可能不是浮点数,例如 10、10.89、99.09 或简单的 0.但我希望返回真实有效的统计数据.
I ask because some numbers may or may not be floats such as, 10, 10.89, 99.09, or simply 0. But I would like true and valid statistical data to be returned.
我可以依靠浮点数学吗?
Can I rely on floating point math for this?
编辑
我知道这是一个笼统的问题,我深表歉意,但对于像我这样的非数学家,我也不是 MYSQL 专家,我希望得到该领域专家的意见.
I know this is a generic question, and I apologise extensively, but for non mathematicians like myself, also I am not a MYSQL expert, I would like an opinion of an expert in this field.
我已经完成了我的研究,但我仍然觉得我对这件事有一个模糊的判断.如果我的问题离题或不适合本网站,我再次道歉.
I have done my research but I still feel I have a clouded judgement on the matter. Again I apologise if my question is off topic or not suitable for this site.
推荐答案
这个link 很好地解释了您要查找的内容.内容如下:
This link does a good job of explaining what you are looking for. Here is what is says:
所有这三种类型,都可以通过以下参数(大小,d)指定.其中 size 是 String 的总大小,d 表示精度.例如,要存储像 1234.567 这样的数字,您需要将数据类型设置为 DOUBLE(7, 3),其中 7 是总位数,3 是小数点后的位数.
All these three Types, can be specified by the following Parameters (size, d). Where size is the total size of the String, and d represents precision. E.g To store a Number like 1234.567, you will set the Datatype to DOUBLE(7, 3) where 7 is the total number of digits and 3 is the number of digits to follow the decimal point.
FLOAT 和 DOUBLE,都表示浮点数.FLOAT 用于单精度,而 DOUBLE 用于双精度数字.从 0 到 23 的精度会产生一个 4 字节的单精度 FLOAT 列.从 24 到 53 的精度会产生一个 8 字节的双精度 DOUBLE 列.FLOAT 精确到小数点后 7 位,DOUBLE 精确到 14 位.
FLOAT and DOUBLE, both represent floating point numbers. A FLOAT is for single-precision, while a DOUBLE is for double-precision numbers. A precision from 0 to 23 results in a 4-byte single-precision FLOAT column. A precision from 24 to 53 results in an 8-byte double-precision DOUBLE column. FLOAT is accurate to approximately 7 decimal places, and DOUBLE upto 14.
Decimal 的声明和作用类似于 Double.但是浮点值和十进制(数字)值之间存在很大差异.我们使用 DECIMAL 数据类型来存储精确的数值,我们不需要精确但精确和准确的值.Decimal 类型最多可存储 65 位,小数点后 30 位.
Decimal’s declaration and functioning is similar to Double. But there is one big difference between floating point values and decimal (numeric) values. We use DECIMAL data type to store exact numeric values, where we do not want precision but exact and accurate values. A Decimal type can store a Maximum of 65 Digits, with 30 digits after decimal point.
因此,对于最准确和最精确的值,十进制将是最佳选择.
相关文章