2016-03-22 122 views
0

我有一個程序,我設置的值作爲四捨五入高達9位小數

DECLARE V_FACTOR DECIMAL(14,9); 

SET V_FACTOR = ROUND((73108997572.52/69453547621393.89),9); 

應該給我像0.001052632的值,但其付出的0.00105

+0

你在那裏看起來很對我 –

+0

應該工作 - 你在命令行還是在GUI上運行它?有時GUI會削減結果... – MichaelTiefenbacher

+0

上面的代碼是存儲過程的一部分,並在數據庫上運行。沒有涉及的GUI。 –

回答

0

我跑了下面的測試。

創建一個源文件round.sql。

--#SET TERMINATOR @ 
connect to [email protected] 

values (ROUND((73108997572.52/69453547621393.89),9))@ 

create or replace procedure stack.round_proc(out r decimal(14,9)) 
language sql 
begin 
    declare r1 decimal(14,9); 
    set r = ROUND((73108997572.52/69453547621393.89),9); 
end 
@ 

create or replace function stack.round_func() 
returns decimal(14,9) 
language sql 
begin atomic 
    declare r1 decimal(14,9); 
    set r1 = ROUND((73108997572.52/69453547621393.89),9); 
    return r1; 
end 
@ 

call stack.round_proc(?)@ 

values (stack.round_func())@ 

connect [email protected] 
[email protected] 

執行的源文件,使用:

db2 -tvf round.sql > round.out 2>&1 

結果round.out捕獲:

connect to pocdb 

    Database Connection Information 

Database server  = DB2/LINUXX8664 10.5.3 
SQL authorization ID = DB2INST1 
Local database alias = POCDB 


values (ROUND((73108997572.52/69453547621393.89),9)) 

1 
--------------------------------- 
      0.001052632000000000 

    1 record(s) selected. 


create or replace procedure stack.round_proc(out r decimal(14,9)) 
language sql 
begin 
    declare r1 decimal(14,9); 
    set r = ROUND((73108997572.52/69453547621393.89),9); 
end 

DB20000I The SQL command completed successfully. 

create or replace function stack.round_func() 
returns decimal(14,9) 
language sql 
begin atomic 
    declare r1 decimal(14,9); 
    set r1 = ROUND((73108997572.52/69453547621393.89),9); 
    return r1; 
end 

DB20000I The SQL command completed successfully. 

call stack.round_proc(?) 

    Value of output parameters 
    -------------------------- 
    Parameter Name : R 
    Parameter Value : 0.001052632 

    Return Status = 0 

values (stack.round_func()) 

1 
---------------- 
    0.001052632 

    1 record(s) selected. 


connect reset 
DB20000I The SQL command completed successfully. 

terminate 
DB20000I The TERMINATE command completed successfully. 

如果您收到的結果是不同的,你應該打開一個PMR。

+0

我得到了問題,出來參數註冊是十進制(14,5),這導致了這個問題。感謝您的幫助.. –

+0

很高興您能夠得到一個解決方案。快樂的編碼! –