09-05-2006 10:42 AM
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.
09-05-2006 10:44 AM
i think for division or multiplication u have to check.
fixed point arthimetic
or u have to multiply by content to display right position.
it means if it truncate 2 decimal place multiply by 100...
09-05-2006 10:46 AM
soppuse num3 = num1/num2..
take num1,num2,num3 as same type..
then it works fine...
if it is not working pls post ur code part how u assiened and how u r calculating...then we resolve it..ok
Ramesh.
09-05-2006 11:03 AM
parameters: p_1 type p decimals 2,
p_2 type p decimals 2.
data p_3 type p decimals 2.
p_3 = p_2 / p_1 .
Enter these values for p_1 and p_2 as my user settings permits ',' as decimal.
p_1 = '30,50'.
p_2 = '71,00'.
i should get p_3 value as 0,50 without using that fixed point arthimetic on.
09-05-2006 10:48 AM
Check the type of your destination variant. If it is only TYPE I (integer) that will cut the decimals off. Use TYPE P for the destination variable also.
Happy developing...
09-05-2006 10:51 AM
Hi,
declare target field as follows
data :target type p decimals 3.
target = s1 / s2.
If target field defined is small than output is
truncated.
Declare your target field with no of decimals
places required.
Regards
Amole
09-07-2011 9:33 AM
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