本文介绍了DB2十进制除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我很难在DB2存储过程中进行简单的划分.

我正在使用Data Studio并正在使用DB2 z/OS v9.1

我的变量:
-------------
值小数(18,13)
total_value十进制(18,13)
小数百分比(12,9)

简单划分:
--------------
百分比=值/总值* 100

我的价值观:
----------
值= 45.23
total_value = 57.35

预期结果:
----------------
百分比= 78.866608544

我将百分比设为零.花了几个小时浏览后,我发现

http ://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic =/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_decimaldivision.htm [ ^ ]

我无法完全理解,但发现它与精度和规模有关.
然后我玩了,最后我通过
得到了结果(cast(值作为小数(15,13))/cas(总值作为小数(22,9))*100.

现在我发现我不应该抛弃那些价值观.

还有其他无需铸造就可以得到结果的方法吗??
请尽快答复.......寻找解决方案

Hi All,

I am having tough time doing a simple division in DB2 Stored procedure.

I am using Data studio and working on DB2 z/OS v9.1

My variables:
-------------
value Decimal(18,13)
total_value Decimal(18,13)
Percentage Decimal(12, 9)

Simple Division:
--------------
Percentage= value/total_value * 100

My values:
----------
value = 45.23
total_value = 57.35

Expected Result:
----------------
percentage = 78.866608544

I am getting the percentage as zero. After spending few hrs on browsing I found

http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db2z10.doc.sqlref/src/tpc/db2z_decimaldivision.htm[^]

I couldn''t able to understand completely but figured out it has to do with precision and scale.
then I played with it and finally i got the result by doing
(cast(value as decimal(15,13)) / cas(total_value as decimal(22,9)) * 100.

Now i found that i am not supposed to cast those values .

Is there any other way of getting result without casting????
Please respond ASAP.......Looking after the solution

推荐答案

Percentage Decimal(12, 9)


使用


use

Percentage Decimal(18, 13)


或更高.


or higher.


这篇关于DB2十进制除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 13:33