阅读oracle后错误的jython float精度

时间:2017-05-18 08:53:32

标签: oracle jython

我遇到了从oracle读取浮点数的问题。 我有以下代码段:

sqlstr='select prio from tabletest'
statement = None
if connection is not None:
    try:
        statement = connection.prepareStatement(sqlstr)
        if connection is not None:
            rs = statement.executeQuery()
            if rs is not None:
                #statement.closeOnComplete()
                while (rs.next()):
                    NWW = rs.getFloat(1)
                    print (NWW)
                rs.close()
            else:
                statement.close()
  except:
        pass
    finally:
        connection.close()

这让我知道了:

 0.5
 0.5
 0.5
 0.20000000298
 0.5
 0.990000009537
 0.5
 0.5
 0.699999988079

但我在db中的实际数据如下所示:

0,5
0,5
0,5
0,2
0,5
0,99
0,5
0,5
0,7

db定义为:

  CREATE TABLE "SYSTEM"."tabletest" 
   (        "NWW" NUMBER(12,8)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSTEM" ;

正如你所看到的,浮点数只是精确的prio = 0.5 ...有没有我可以设置浮点精确的选项?

感谢, 即

1 个答案:

答案 0 :(得分:0)

...有点尴尬,但rs.getDouble(1)解决了我的问题。 :)