I'm using 2 packed numbers. And fixed point arthimetic is not checked in my program and i don't want to check that. While dividing these two numbers the decimal portion is getting truncated.
How to resolve this problem?
I've tried moving the number to a character variable but this is of no use if the user follows the decimal notation as ',' then the division throws dump.
Please help me.
Hello all,
When you can't use "fixed point arthimetic" you have to calculate factor that will allow you to get the right value because packed numbers are considered as integers.
As an example: (consider that we don't know decimals number of each variable)
DATA : wl_dec1 type i,
wl_dec2 type i,
wl_dec3 type i,
wl_factor type i.
DESCRIBE FIELD klmeng decimals wl_dec1.
DESCRIBE FIELD zzntgew decimals wl_dec2.
DESCRIBE FIELD ntgew decimals wl_dec3.
wl_factor = 10 ** ( wl_dec1 + wl_dec2 - wl_dec3 ). " thisformula is different in case of division
ntgew = klmeng * zzntgew / wl_factor.
In case of division it should be :
wl_factor = 10 ** ( wl_dec1 - wl_dec2 + wl_dec3 ). "where wl_decx correspond to varx decimals
var1 = var2 / var3 * wl_factor.
As a solution you can also create a function module which uses "fixed point aritmetic" in which you send values as parameters and use wanted formula as single as you would write without any conversion factor.
Edited by: blsapsdn on Sep 7, 2011 11:45 AM
Add a comment