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

Division by 100

Former Member
0 Likes
2,237

Hi Experts,

I have probelem in division with 100

eg if i have a variable 12.87

x=12.87

if i divide this variable by 100

y = 12.87/100

the value becomes 13 , but the requirement is to be 12

the value of y finally should be 12

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,722

Hi,

The result is just rounded ie., 0.1287 is rounded to 0.13.

Also try like:



DATA: y TYPE p DECIMALS 2.
DATA: x TYPE p DECIMALS 2 VALUE '12.87'.

y = x / 100 .

WRITE : y.

Regards...

5 REPLIES 5
Read only

Former Member
0 Likes
1,722

hi,

If i have understood your requirement correctly ...do this way ...


data : v_x(5) type c value '12.87',
         v_y(5) type c,
         v_z(5) type c.

SPLIT v_x AT '.' INTO v_y v_z.
write : v_x, v_y, v_z. 

Read only

Former Member
0 Likes
1,722

Hi Karthik,

It is rounding off the decimal values and hence making it 13 in your case.

What are the variable types that you declared for X and Y ?

You should be taking the value after division into an integer variable and it shall give you the required number.

Reward points if this helps,

Kiran

Read only

Former Member
0 Likes
1,722

You have to use some math functions here for to get integer value in your final format just use TRUNC key word.

like after dividing you just say:

y = trunc(y).

then you will get integer part means 12.

try this if it useful ..reward.

Dara.

Read only

Former Member
0 Likes
1,723

Hi,

The result is just rounded ie., 0.1287 is rounded to 0.13.

Also try like:



DATA: y TYPE p DECIMALS 2.
DATA: x TYPE p DECIMALS 2 VALUE '12.87'.

y = x / 100 .

WRITE : y.

Regards...

Read only

Former Member
0 Likes
1,722

Hi,

Insted of using y = 12.87/100

you can use y = 12.87 DIV 100.

Then it will return 12.

Definitely it will work.