Application Development 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: 

Round off to two decimal places

Former Member
0 Kudos

hi

i have a filed in it values are there i want to round off to two decimal places

which is the function module for it please suggest

regards

Arora

1 ACCEPTED SOLUTION

Former Member

Hi Arora,

Check this sample code.

DATA: WA_INPUT TYPE P DECIMALS 8,
WA_OUTPUT TYPE P DECIMALS 2.

WA_INPUT = '5678.65800341'.

CALL FUNCTION 'ROUND'
 EXPORTING
  INPUT = WA_INPUT
  IMPORTING
  OUTPUT = WA_OUTPUT
 EXCEPTIONS
  INPUT_INVALID = 1
  OVERFLOW = 2
  TYPE_INVALID = 3
  OTHERS = 4.

IF SY-SUBRC 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF.
WRITE: WA_OUTPUT.

4 REPLIES 4

Former Member

Hi Nishant Arora,

Please check this code.


DATA: N1 TYPE P DECIMALS 4 VALUE '0.0565',
           N2 TYPE P DECIMALS 2.

MOVE N1 TO N2.
WRITE: N2.

Here the value is get rounded to 0.06.

Rather than function modules you go with this. I think it is easier.

Reward points if useful.

Cheers,

Swamy Kunche

Former Member

Hi Arora,

Check this sample code.

DATA: WA_INPUT TYPE P DECIMALS 8,
WA_OUTPUT TYPE P DECIMALS 2.

WA_INPUT = '5678.65800341'.

CALL FUNCTION 'ROUND'
 EXPORTING
  INPUT = WA_INPUT
  IMPORTING
  OUTPUT = WA_OUTPUT
 EXCEPTIONS
  INPUT_INVALID = 1
  OVERFLOW = 2
  TYPE_INVALID = 3
  OTHERS = 4.

IF SY-SUBRC 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF.
WRITE: WA_OUTPUT.

Former Member
0 Kudos

solved

Former Member
0 Kudos

Hi All

Use the below code and it is so simple

For 2 decimal places

data(lv_round) = round(  val = '5678.65800341' dec = 2  ).


lv_round will be 5678.66


data(lv_round) = round(  val = '5678.65300341' dec = 2  ).


lv_round will be 5678.65


For 5 decimals


data(lv_round) = round(  val = '5678.65800741' dec = 5 ).


lv_round will be 5678.65801


data(lv_round) = round(  val = '5678.65800341' dec = 5 ).


lv_round will be 5678.65800


Thanks,

Murugan