float datatype in Oracle database

作了一个测试,就像我们以前一直提醒的一样。在使用非 number datatype 的 数字类型一定要注意。
create table t_float (f float(2),n number(2))
SQL> insert into t_float values (7,7);
1 row created.
SQL> insert into t_float values (11,11);
1 row created.
SQL> insert into t_float values (99,99)
1 row created.
SQL> select * from t_float;
F N
---------- ----------
7 7
10 11
100 99
Why:
a FLOAT column with a binary precision of 2 bits, is implemented as a NUMBER column with 1 decimal digit of precision and no fixed scale. Thus the number 7, which requires 3 binary bits, will nevertheless be stored exactly, whereas the number 11, which has two decimal digits, will be rounded to 10 because only one decimal digit of precision is allowed.
It is legitimate for a database implementation to use higher precision than requested in this way. Therefore, database applications should always round data values explicitly when required, and should not rely on the precision of the datatype to round data implicitly.
暂时还有理解上面的含义 :(
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/34596/viewspace-805109/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/34596/viewspace-805109/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值