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

simple division query

Former Member
0 Likes
2,133

Hi All,

I have simple query ...When i do division like 5/2 then answer will be whole number as 3....I am doing division of odd number with 2 but in that case i want answer to appear as earlier number e.g. if i divide 5/2 then i want answer as 2.

Is it possible ???...if yes how??

thnx.

1 ACCEPTED SOLUTION
Read only

former_member188827
Active Contributor
0 Likes
1,817

data res type p DECIMALS 0.

res = trunc( 5 / 2 ) .

write res.

i am taking data type as i only , even i tried num but not getting desired output.

8 REPLIES 8
Read only

sridhar_meesala
Active Contributor
0 Likes
1,817

Hi,

Do not take the output field type as type P. Take it as integer type and try.

Thanks,

Sri.

Read only

0 Likes
1,817

i am taking data type as i only , even i tried num but not getting desired output.

Read only

0 Likes
1,817

Hi,

Try this,

data : num1 TYPE p VALUE 2,
          num2 TYPE p VALUE 5,
          num3 TYPE p .

num3 = trunc( num2 / num1 ).
WRITE num3.

Thanks,

Sri.

Read only

0 Likes
1,817
DATA : p1 TYPE i, p2 type p DECIMALS 2.
p2 =  5 / 2.
p1 = floor( p2 ).

WRITE p1.
Read only

former_member188827
Active Contributor
0 Likes
1,818

data res type p DECIMALS 0.

res = trunc( 5 / 2 ) .

write res.

Read only

Former Member
0 Likes
1,817

Hi,

Check this



DATA: a TYPE p DECIMALS 0,
      b TYPE p DECIMALS 0.
a = 5 / 2.
b = floor( a ).
WRITE: b.

Or



DATA: a TYPE i,
      b TYPE i.
a = 5 / 2.
WRITE: a.

Read only

Former Member
Read only

Former Member
0 Likes
1,817

Hi,

Check out the code below.

data : num type p value 5 decimals 2.

data : num1 type p value 2 decimals 2,

div type p decimals 2, div1 type i.

div = num / num1 .

div1 = floor( div ).

write div1.

Hope it will solve.

Regards

Raghu