我有一个程序,我设置的值作为四舍五入高达9位小数
DECLARE V_FACTOR DECIMAL(14,9);
SET V_FACTOR = ROUND((73108997572.52/69453547621393.89),9);
应该给我像0.001052632的值,但其付出的0.00105
我有一个程序,我设置的值作为四舍五入高达9位小数
DECLARE V_FACTOR DECIMAL(14,9);
SET V_FACTOR = ROUND((73108997572.52/69453547621393.89),9);
应该给我像0.001052632的值,但其付出的0.00105
我跑了下面的测试。
创建一个源文件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。
我得到了问题,出来参数注册是十进制(14,5),这导致了这个问题。感谢您的帮助.. –
很高兴您能够得到一个解决方案。快乐的编码! –
你在那里看起来很对我 –
应该工作 - 你在命令行还是在GUI上运行它?有时GUI会削减结果... – MichaelTiefenbacher
上面的代码是存储过程的一部分,并在数据库上运行。没有涉及的GUI。 –