‎2007 Apr 30 5:08 PM
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?
‎2007 Apr 30 5:16 PM
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
‎2007 Apr 30 5:15 PM
You can use the function call ROUND & control the rounding up/down.
~Suresh
‎2007 Apr 30 5:16 PM
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
‎2007 Apr 30 5:19 PM
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
‎2007 Apr 30 5:24 PM
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.
‎2007 Apr 30 5:31 PM
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
‎2007 Apr 30 6:28 PM
Hi,
You can use data type as P(for Packed Decimal) with Decimal 2.
Regards,
Bhaskar