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

truncate numbers

Former Member
0 Likes
907

i would like the syntax to truncate numbers to 2 decimal places. eg

(456/700) *100 will give me 65.142857142857142857

thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
781

Hi,

data:res type p decimals 2

res = (456/700) *100

store the result in res varaible

Rewards If Useful

Regards

Hi,

data:res type p decimals 2

res = (456/700) *100

store the result in res varaible

Rewards If Useful

Regards

5 REPLIES 5
Read only

Former Member
0 Likes
782

Hi,

data:res type p decimals 2

res = (456/700) *100

store the result in res varaible

Rewards If Useful

Regards

Read only

Former Member
0 Likes
781

Try this :

DATA: cal(9) TYPE p DECIMALS 2.

cal = ( 456 / 700 ) * 100.

Read only

Former Member
0 Likes
781

Hi,

Create a packed variable with 2 decimals and pass the result to this variable, it will be automatically truncated to 2 decimals.

DATA: v_res(8) TYPE p DECIMALS 2.

v_res = (456/700) *100 .

Rewards points if helpful.

Regards,

Srinivas Ch

Read only

Former Member
0 Likes
781

Hi Tendai,

check this code..

DATA: num1 TYPE f, num2 TYPE p DECIMALS 2.

num1 = '1.666666'.

num2 = num1.

WRITE num2.

Reward points if helpful..

Regards,

Goutham.

Read only

Former Member
0 Likes
781

Hi Tendai,

Declare a varibale to type P with decimals 2.

DATA : result TYPE p DECIMALS 2.

Now store the result of your expression in the variable declared above.

result = (456/700) *100.

Now out the result you will find the result in your desired format.

WRITE : / result.

Reward if useful.

Regards,

Chandru