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 FM and keyword issue

Former Member
0 Kudos

Hi,

     I have a result that needs rounding.

     The result on two different occassions are 0.1147 and 22.7919 (Input)

     After rounding, the expected values are 0.12 and 22.79 (Output)

     I tried, Round keyword as follows:

         output =  round( val = input dec = 2 mode = 1 )

     It generates the below outputs 

          When input = 0.1147, output is 0.12 and (as expected)

          When input = 22.7919, output is 22.8      (not expected)

     I tried the ROUND FM as follows:

     CALL FUNCTION 'ROUND'
            EXPORTING
                  DECIMALS    = 2
                  INPUT            = input
                  SIGN              = 'X'
           IMPORTING
                  OUTPUT         = output

     It generates the below outputs:

          When input = 0.1147, output is 0.11 and (not expected)

          When input = 22.7919, output is 22.79    (not expected)

     Can anyone please suggest a way to get the expected outputs (0.12, 22.79)

Regards.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Joshva,

Change decimal places to '3' instead of '2'.

DATA: i1       TYPE p DECIMALS 4,

          o1      TYPE p DECIMALS 2,

          i2       TYPE p DECIMALS 4,

          o2       TYPE p DECIMALS 2.

i1 = '0.1147'.

i2 = '22.7919'.

CALL FUNCTION 'ROUND'

  EXPORTING

    decimals = 3

    input    = i1

    sign     = '+'

  IMPORTING

    output   = o1.

WRITE: o1.

CALL FUNCTION 'ROUND'

  EXPORTING

    decimals = 3

    input    = i2

    sign     = '+'

  IMPORTING

    output   = o2.

.

WRITE: o2.

Hope this helps,

Thanks

VM

2 REPLIES 2

Former Member
0 Kudos

Joshva,

Change decimal places to '3' instead of '2'.

DATA: i1       TYPE p DECIMALS 4,

          o1      TYPE p DECIMALS 2,

          i2       TYPE p DECIMALS 4,

          o2       TYPE p DECIMALS 2.

i1 = '0.1147'.

i2 = '22.7919'.

CALL FUNCTION 'ROUND'

  EXPORTING

    decimals = 3

    input    = i1

    sign     = '+'

  IMPORTING

    output   = o1.

WRITE: o1.

CALL FUNCTION 'ROUND'

  EXPORTING

    decimals = 3

    input    = i2

    sign     = '+'

  IMPORTING

    output   = o2.

.

WRITE: o2.

Hope this helps,

Thanks

VM

0 Kudos

Thanks Venkat.

It worked.