mysql 中 float(2,2) 和 float() 的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7979912/
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
Difference between float(2,2) and float() in mysql
提问by ARUN P.S
I created a table in MySQL with a column of type float(2,2) and inserted value 10 into the same, but I found that the value stored is 0.99.
我在 MySQL 中创建了一个带有 float(2,2) 类型列的表,并将值 10 插入其中,但我发现存储的值是 0.99。
What is the reason behind this ? If we use a column of type float(m, n) in MySQL where 'm' and 'n' are integers, then what should I watch out for when storing values in this column ?
这背后的原因是什么?如果我们在 MySQL 中使用 float(m, n) 类型的列,其中 'm' 和 'n' 是整数,那么在此列中存储值时应该注意什么?
回答by Konerak
float(2,2)
means "use two digits, of which two are used after the decimal point".
float(2,2)
意思是“用两位数,其中两位用在小数点后”。
Hence, you can go from -0.99 to 0.99. You can't insert 10 into this column, you'd need atleast two digits before the comma (so float(4,2) or float(2,0)).
因此,您可以从 -0.99 到 0.99。您不能在此列中插入 10,您需要在逗号前至少有两位数字(因此是 float(4,2) 或 float(2,0))。
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. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.
MySQL 允许使用非标准语法:FLOAT(M,D) 或 REAL(M,D) 或 DOUBLE PRECISION(M,D)。这里的“(M,D)”是指最多可以存储M位的数值,其中D位可能在小数点后。例如,定义为 FLOAT(7,4) 的列在显示时看起来像 -999.9999。MySQL 在存储值时执行四舍五入,因此如果将 999.00009 插入 FLOAT(7,4) 列,则近似结果为 999.0001。
回答by Francis
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位可能在小数点后。
回答by Madushanka kahawa
In MySql, There are data type like FLOAT(M,D).Where D is the number of decimals and M is the total number of digits (including decimals).Decimal precision can go to 24 places for a FLOAT and M range 1 to 65. If syntax is FLOAT(2,2), then there have only two decimal place and no place to real number.So you want to add 10 you can use like FLOAT(5,2).
在 MySql 中,有 FLOAT(M,D) 之类的数据类型。其中 D 是小数位数,M 是总位数(包括小数)。对于 FLOAT,小数精度可以达到 24 位,M 范围为 1 到65.如果语法是FLOAT(2,2),那么小数点后只有两位,实数没有位置。所以你想加10你可以像FLOAT(5,2)一样使用。
回答by firefly
float(M,D) this keeping in mind here M=max. no. of digit allowed(range 1 to 65), D=no. of digits after the decimal point. so cany you change it float(5,2). so float(2,2) does not satisfiy your need to enter no.10
float(M,D) 记住这里 M=max。不。允许的位数(范围 1 到 65),D=no。小数点后的位数。所以你可以改变它浮动(5,2)。所以 float(2,2) 不能满足您输入 10 号的需要