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

problem with decimals

Former Member
0 Likes
804

hello all,

I am having a field that has type p decimals 1. now i need to format this field in a specific manner.

if the value is 4.0 then i want to output 4 and if output is 5.6 then i want to output 5.6.

i was wondering how to achieve the formal. I tried "shift right" but dint work; One of the possible solution is checking the last digit and if it is 0 and then is preceded by point i need to delete both of the digits. any other solutions??

will wait for your expert input.

thanks and regards,

Gaurav.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
735
given the input as 4.0 it will give 4,
       

REPORT ychatest LINE-COUNT 50.


DATA : dec TYPE p DECIMALS 1,
       dec1 TYPE p DECIMALS 1,
       dec3 TYPE i.

dec = '4.0'.

dec1 = frac( dec ).

IF dec1 EQ '0.0'.
  dec3 = dec.
ENDIF.

WRITE : dec3.
5 REPLIES 5
Read only

Former Member
0 Likes
735

i´d do following:

data lv_swap type i.

data lv_out type c length 10.

lv_check = your_value mod 1.

if lv_check = 0.

lv_swap = your_value.

lv_out = lv_swap.

else.

lv_out = your_value.

endif.

Read only

Former Member
0 Likes
736
given the input as 4.0 it will give 4,
       

REPORT ychatest LINE-COUNT 50.


DATA : dec TYPE p DECIMALS 1,
       dec1 TYPE p DECIMALS 1,
       dec3 TYPE i.

dec = '4.0'.

dec1 = frac( dec ).

IF dec1 EQ '0.0'.
  dec3 = dec.
ENDIF.

WRITE : dec3.
Read only

Former Member
0 Likes
735

Looked at various formatting options in the WRITE statement, but couldnt come up with any clean solution. Of course, there is a solution, it's just not clean!

data: v_num type p decimals 1.

data: v_chr(5) type c.

v_num = 4.

write v_num to v_chr.

write:/ v_chr.

shift v_chr right deleting trailing space.

shift v_chr right deleting trailing '.0'.

write:/ v_chr.

v_num = '5.6'.

write v_num to v_chr.

write:/ v_chr.

shift v_chr right deleting trailing space.

shift v_chr right deleting trailing '.0'.

write 😕 v_chr.

OUTPUT:

4.0

4

5.6

5.6

Read only

Former Member
0 Likes
735

Hi Gaurav,

<b>Run the below code to get u r expected result.</b>

Report zex33.
parameter : p_d TYPE p DECIMALS 1.
DATA :
       v_d1(20) ,
       v_d2 TYPE i.

v_d1 = p_d.

search v_d1 for '.0'.
if sy-subrc eq 0.
   v_d2 = p_d.
   write : / v_d2.
else.
   v_d1 = p_d.
   write : / v_d1.
endif.

Read only

Former Member
0 Likes
735

hello all, thanks for ur kind replies.

florian your method works , i tried but it was tedious for me to encompass it in my program.

deepak : i mentioned in program that shift right is not working however thgh thanks for ur reply.

chandrasekhar and sreekant, ur technique works. although i used chandrakant's technique since it is based on standard function of SAP.

thanks once again to all of u, i have tried to give points in a fair manner, apologies if i disappoint you.

thanks,

Gaurav