MySQL mysql中的双数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21576816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
double datatype in mysql
提问by Ripa Saha
I am defining one of my column's length as double(16,2). Here 16 is not fixed. But 2 is fixed. Though display length(16) will vary depending on calculation. So I want to make it variable length.
我将我的专栏的长度之一定义为double(16,2)。这里 16 不是固定的。但是2是固定的。虽然显示长度(16)会因计算而异。所以我想让它变长。
Now my question is - Are there any way to define only floating point no (i.e. 2 from my example) and display length(16) as variable. Because I don't want to occupy unnecessary space.
现在我的问题是 - 有没有办法只定义浮点数(即我示例中的 2)并将长度(16)显示为变量。因为我不想占用不必要的空间。
回答by developerCK
The FLOAT and DOUBLE types represent approximate numeric data values.
FLOAT 和 DOUBLE 类型表示近似数值数据值。
MySQL uses four bytes for single-precision values and eight bytes for double-precision values.
MySQL 对单精度值使用四个字节,对双精度值使用八个字节。
MySQL also supports this optional precision specification, but the precision value is used only to determine storage size. 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.
MySQL 也支持这个可选的精度规范,但精度值仅用于确定存储大小。0 到 23 之间的精度会产生一个 4 字节的单精度 FLOAT 列。从 24 到 53 的精度会产生一个 8 字节的双精度 DOUBLE 列。
MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here, “(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.
MySQL 允许使用非标准语法:FLOAT(M,D) 或 REAL(M,D) 或 DOUBLE PRECISION(M,D)。这里的“(M,D)”是指最多可以存储M位的数值,其中D位可能在小数点后。
FLOAT:
漂浮:
A small (single-precision) floating-point number. Permissible values are -3.402823466E+38 to -1.175494351E-38, 0, and 1.175494351E-38 to 3.402823466E+38. These are the theoretical limits, based on the IEEE standard. The actual range might be slightly smaller depending on your hardware or operating system. A single-precision floating-point number is accurate to approximately 7 decimal places. This is not required and will default to 10,2,(If M and D are omitted, values are stored to the limits permitted by the hardware.)
一个小的(单精度)浮点数。允许的值为 -3.402823466E+38 到 -1.175494351E-38、0 和 1.175494351E-38 到 3.402823466E+38。这些是基于 IEEE 标准的理论限制。实际范围可能略小,具体取决于您的硬件或操作系统。单精度浮点数精确到大约 7 个小数位。这不是必需的,默认为10,2,(如果省略 M 和 D,则值存储在硬件允许的范围内。)
DOUBLE:
双倍的:
M is the total number of digits and D is the number of digits following the decimal point. If M and D are omitted, values are stored to the limits permitted by the hardware. A double-precision floating-point number is accurate to approximately 15 decimal places. This is not required and will default to 16,4, where 4 is the number of decimals. ( If M and D are omitted, values are stored to the limits permitted by the hardware. )
M是总位数,D是小数点后的位数。如果省略 M 和 D,则将值存储到硬件允许的限制范围内。双精度浮点数精确到大约 15 位小数。这不是必需的,默认为16,4,其中 4 是小数位数。(如果省略 M 和 D,则将值存储到硬件允许的限制范围内。)
For more http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
更多 http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html
回答by Joni
The MySQL DOUBLE
data type occupies 8 bytes of storageno matter what numbers you store in it.
无论您在其中存储什么数字,MySQLDOUBLE
数据类型都占用 8 字节的存储空间。