我应该使用什么MYSQL数据类型来存储64位双精度?

时间:2022-02-20 16:01:20

I want to store traditional 64-bit floating points but I am confused with all the various options I have in MYSQL e.g. FLOAT(M,D), REAL(M,D), DOUBLE(M,D), FLOAT, DOUBLE PRECISION(M,D), REAL, DOUBLE, DECIMAL(M,D) and NUMERIC. Which one is best suited to store double precision floating point formats? If I need to specify M or D, what should I specify?

我想存储传统的64位浮点数,但我对MYSQL中所有的选项感到困惑,比如FLOAT(M,D)、REAL(M,D)、DOUBLE(M,D)、FLOAT、DOUBLE PRECISION(M,D)、REAL、DOUBLE、DECIMAL(M,D)和NUMERIC。哪一种最适合存储双精度浮点格式?如果我需要指定M或D,我应该指定什么?

1 个解决方案

#1


2  

To store a 64 bit (8 byte) floating point number, use DOUBLE PRECISION or its alias/equivalent DOUBLE. They are the same. FLOAT is a single-precision 32-bit number, and REAL might be either one, depending on server config, so stay away from that one.

要存储64位(8字节)浮点数,请使用双精度或其别名/等效双精度。他们是相同的。FLOAT是一个单精度的32位数字,根据服务器配置,REAL可能是其中之一,所以要远离这个数字。

Don't specify the (M,D) values unless you have a reason to, because then you're not getting a "traditional" 64-bit number.

除非你有理由,否则不要指定(M,D)值,因为那样你就不会得到一个“传统的”64位数字。

Standard disclaimer, don't use any of these -- use DECIMAL instead -- unless you fully understand the inherent imprecision of floating point number storage and operations. Money values, for example, are almost always candidates for a DECIMAL column.

标准的免责声明,不要使用其中任何一种——而是使用DECIMAL——除非您完全理解浮点数存储和操作的固有不精确。例如,货币值几乎总是小数列的候选值。

http://dev.mysql.com/doc/refman/5.7/en/numeric-types.html

http://dev.mysql.com/doc/refman/5.7/en/numeric-types.html

http://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html

http://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html

#1


2  

To store a 64 bit (8 byte) floating point number, use DOUBLE PRECISION or its alias/equivalent DOUBLE. They are the same. FLOAT is a single-precision 32-bit number, and REAL might be either one, depending on server config, so stay away from that one.

要存储64位(8字节)浮点数,请使用双精度或其别名/等效双精度。他们是相同的。FLOAT是一个单精度的32位数字,根据服务器配置,REAL可能是其中之一,所以要远离这个数字。

Don't specify the (M,D) values unless you have a reason to, because then you're not getting a "traditional" 64-bit number.

除非你有理由,否则不要指定(M,D)值,因为那样你就不会得到一个“传统的”64位数字。

Standard disclaimer, don't use any of these -- use DECIMAL instead -- unless you fully understand the inherent imprecision of floating point number storage and operations. Money values, for example, are almost always candidates for a DECIMAL column.

标准的免责声明,不要使用其中任何一种——而是使用DECIMAL——除非您完全理解浮点数存储和操作的固有不精确。例如,货币值几乎总是小数列的候选值。

http://dev.mysql.com/doc/refman/5.7/en/numeric-types.html

http://dev.mysql.com/doc/refman/5.7/en/numeric-types.html

http://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html

http://dev.mysql.com/doc/refman/5.7/en/floating-point-types.html