存储统计数据,是否需要DECIMAL,FLOAT或DOUBLE? [英] Storing statistical data, do I need DECIMAL, FLOAT or DOUBLE?

查看:152
本文介绍了存储统计数据,是否需要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.

我问,因为一些数字可能是也可能不是但是我想要返回真实有效的统计数据。

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:

所有这三种类型可以通过以下参数(size,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.

十进制的声明和功能类似于Double。但是浮点数和小数(数值)值之间有很大的区别。我们使用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.

所以,为了最精确和最精确的值,十进制将是最佳选择。

这篇关于存储统计数据,是否需要DECIMAL,FLOAT或DOUBLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆