Application Development and Automation 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: 
Read only

Changing decimal places

Former Member
0 Likes
1,968

Hi!

I have a requirement in which I need to change the decimal place of a packed number. The value should not be rounded off. The decimal should be placed after the 10 thousandth place.

For eg. 3349544.88 should be displayed as 33.49.

Please help! Thanks in advance!

1 ACCEPTED SOLUTION
Read only

andreas_mann3
Active Contributor
0 Likes
1,387

Hi,

data z type i value 10000.

data x type p decimals 2.

x = itab-val / i.

Message was edited by: Andreas Mann

Hi!

I have a requirement in which I need to change the decimal place of a packed number. The value should not be rounded off. The decimal should be placed after the 10 thousandth place.

For eg. 3349544.88 should be displayed as 33.49.

Please help! Thanks in advance!

4 REPLIES 4
Read only

Former Member
0 Likes
1,387

Hai Jonathan,

If you are fixed with the number of digits, you can divide the result by a constant to get your answer.

Read only

andreas_mann3
Active Contributor
0 Likes
1,388

Hi,

data z type i value 10000.

data x type p decimals 2.

x = itab-val / i.

Message was edited by: Andreas Mann

Read only

Former Member
0 Likes
1,387

hi,

Use can try with this piece of code.

data: v_pack(10) type p decimals 2 value '3349544.8',
       v_str(10) type c.

unpack v_pack to v_str.
shift v_str right by 5 places.
pack v_str to v_pack.
set country 'US'.
write :/ v_pack.        "33.49

Regards,

Sailaja.

Read only

Former Member
0 Likes
1,387

The below logic would work...if you always have 2 decimals.

unpack lval to lchr.

shift lchr right by 5 places.

write : / lchr using edit mask 'RR_____.__'.

*Use can use the format depending on the length of your *pack field

In case you have more variable decimal length.

lint = lp2.

unpack lint to lchr.

shift lchr right by 3 places.

write : / lchr no-zero using edit mask 'RR____.__'.

Regards

Anurag

-Just wanted you to check that if you use the divide by 100000 you can get rounding issues

Message was edited by: Anurag Bankley

Message was edited by: Anurag Bankley