2017-05-18 41 views
0

我遇到了從oracle讀取浮動的問題。 我有下面的代碼片段:閱讀oracle後錯誤的jython float精度錯誤

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 

分貝定義爲:

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 ...有什麼選擇,我可以設置浮體精確?

感謝, E.

回答

0

...有點尷尬,但rs.getDouble(1)解決了我的問題。 :)