Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with packed numbers

Former Member
0 Kudos

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.

6 REPLIES 6

Former Member
0 Kudos

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...

Former Member
0 Kudos

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.

0 Kudos

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.

Former Member
0 Kudos

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...

Former Member
0 Kudos

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

brice_lagaly
Participant
0 Kudos

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