Skip to Content
avatar image
Former Member

Round off to two decimal places

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 12, 2008 at 12:26 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 12, 2008 at 10:50 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 15, 2008 at 12:06 PM

    solved

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 10, 2016 at 10:50 AM

    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

    Add comment
    10|10000 characters needed characters exceeded