float与decimal的区别

juventus821023 2009-03-10 02:44:55
(used_gas decimal(2,0) unsigned);

(used_gas float(2,0) unsigned);
从DB侧来判断,应该是不相等的,
它们的不同点,也就是说,为什么不相等,
能不能解释说明一下.
谢谢.
...全文
357 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
显灵 2010-08-16
  • 打赏
  • 举报
回复
谢谢!
whf001 2009-09-08
  • 打赏
  • 举报
回复
顶,学习
ckc 2009-03-11
  • 打赏
  • 举报
回复
对mysql 5来说
decimal(p,s)中p最大为65,S最大为30
mysql保存这个数据的时候是把小数点前和小数点后分别保存,你可以理解为用字符串的形式保存
带来的好处是精确,没有不同进制之间小数转换带来的误差
坏处是计算会慢一点
fcoolx 2009-03-11
  • 打赏
  • 举报
回复
没太大区别,但是DECIMAL,5.0.3 版本才开始有

Name: 'FLOAT'
Description:
FLOAT[(M,D)] [UNSIGNED] [ZEROFILL]

A small (single-precision) floating-point number. Allowable 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.

Name: 'DECIMAL'
Description:
DECIMAL[(M[,D])] [UNSIGNED] [ZEROFILL]

For MySQL 5.0.3 and above:

A packed "exact" fixed-point number. M is the total number of digits
(the precision) and D is the number of digits after the decimal point
(the scale). The decimal point and (for negative numbers) the "-" sign
are not counted in M. If D is 0, values have no decimal point or
fractional part. The maximum number of digits (M) for DECIMAL is 65 (64
from 5.0.3 to 5.0.5). The maximum number of supported decimals (D) is
30. If D is omitted, the default is 0. If M is omitted, the default is
10.
wwwwb 2009-03-10
  • 打赏
  • 举报
回复
实际上就是精度不同,在MYSQL HELP中有解释
ACMAIN_CHM 2009-03-10
  • 打赏
  • 举报
回复
1 楼正解。

http://dev.mysql.com/doc/refman/5.1/zh/column-types.html#numeric-types
老哥讲数据库 2009-03-10
  • 打赏
  • 举报
回复
decimal与numeric是同义的,她们是用来精确存储数值的;
float和real是同义的,她们不能精确存储数值.

decimal数据类型最多可存储 38 个数字,它存储了一个准确(精确)的数字表达法,不存储值的近似值。
numeric和decimal数据类型的默认最大精度值是 38。在 Transact-SQL 中,numeric与decimal数据类型在功能上等效。
当数据值一定要按照指定精确存储时,可以用带有小数的decimal数据类型来存储数字。

float和real数据类型被称为近似的数据类型。不存储精确值.当要求精确的数字状态时,比如在财务应用程序中,在那些需要舍入的操作中,或在等值核对的操作中,就不使用这些数据类型。这时就要用integer、decimal、money或smallmone数据类型。
在 WHERE 子句搜索条件中(特别是 = 和 <> 运算符),应避免使用float或real列。最好限制使用float和real列做> 或 < 的比较。
就是这么个意思了大体上,从感性的角度理解,就是这样了.

zings 2009-03-10
  • 打赏
  • 举报
回复
学习....
jackydrl 2009-03-10
  • 打赏
  • 举报
回复
你可以下一本mysql的手册好好看看,在mysql5.1手册的第11章,你看看,其实就是精度不同
http://download.csdn.net/source/1087691

56,685

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧