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

No rounding

Former Member
0 Likes
5,116

I want to convert a number with 2 decimal places(ex: 77.58) to at number with 1 decimal place (ex 77.5). The problem is that by defualt SAP rounds up (ex: 77.6), but I want the number to always be rounded down.

I tried doing this by converting it to a character, but now I can't get the character back into a number with a decimal.

Any ideas?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,426

Hi

You can use the ROUND FM

DATA: v_output TYPE p DECIMALS 1.

DATA: v_input TYPE p DECIMALS 2.

v_input = '77.58'.

<b>CALL FUNCTION 'ROUND'</b>

EXPORTING

decimals = 1

input = v_input

<b>sign = '-'</b>

IMPORTING

output = v_output

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

IF sy-subrc = 0.

<b> WRITE: / v_output.</b>

ENDIF.

Thanks

Naren

6 REPLIES 6
Read only

suresh_datti
Active Contributor
0 Likes
2,426

You can use the function call ROUND & control the rounding up/down.

~Suresh

Read only

Former Member
0 Likes
2,427

Hi

You can use the ROUND FM

DATA: v_output TYPE p DECIMALS 1.

DATA: v_input TYPE p DECIMALS 2.

v_input = '77.58'.

<b>CALL FUNCTION 'ROUND'</b>

EXPORTING

decimals = 1

input = v_input

<b>sign = '-'</b>

IMPORTING

output = v_output

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

IF sy-subrc = 0.

<b> WRITE: / v_output.</b>

ENDIF.

Thanks

Naren

Read only

Former Member
0 Likes
2,426

HI sara,

You can do it this way.

data v_int type i.

v_int = v_num * 10.

v_num = v_num / 10.

write:/ v_num.

Regards,

Ravi

Read only

Former Member
0 Likes
2,426

Hi sara,

1. 77.58 -


> 77.5

77.99 -


> 77.9

(Negative Rounding Concept)

2. Just copy paste

3.

report abc.

data : num type p decimals 2.

data : num1 type p decimals 1.

num = '77.58'.

CALL FUNCTION 'ROUND'

EXPORTING

DECIMALS = 1

INPUT = num

<b>SIGN = '-'</b>

IMPORTING

OUTPUT = num1

EXCEPTIONS

INPUT_INVALID = 1

OVERFLOW = 2

TYPE_INVALID = 3

OTHERS = 4.

write 😕 num1.

regards,

amit m.

Read only

Former Member
0 Likes
2,426

Hi There,

Probably best to use the round function module if it works but the following code seems to do the job:

data: dec2 type p decimals 2 value '22.23',

dec1 type p decimals 1,

ld_str(50) type c.

ld_str = dec2.

SHIFT ld_str right DELETING TRAILING ' '.

shift ld_str right by 1 places.

shift ld_str left DELETING LEADING ' '.

dec1 = ld_str.

Regards

Mart

Read only

Former Member
0 Likes
2,426

Hi,

You can use data type as P(for Packed Decimal) with Decimal 2.

Regards,

Bhaskar