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: 

FM to Round decimal place

Former Member
0 Kudos
7,958

Hi Gurus,

I want to reduce the number of decimal place by rounding off 2 decimal place.

I am using 'HR_NZ_ROUNDING_DECIMALS' function module but its not working,

kindly do the needful.

Regards,

Maithili

14 REPLIES 14

bishwajit_das
Active Contributor
0 Kudos
1,192

Hi,

Use this accordingly....

CALL FUNCTION 'HR_NZ_ROUNDING_DECIMALS' "Round decimals places

  EXPORTING

    value_in =   Input

   conv_dec = 2    

  IMPORTING

    value_out =   Output

  EXCEPTIONS 

     NO_ROUNDING_REQUIRED = 1   

    DECIMALS_GREATER_THAN_10 = 2 

    ROUNDING_ERROR = 3.

Regards,

Bishwajit       

former_member193460
Contributor
1,192


Hi Maithili,

     Check if your system has FM ROUND.

DATA: WA_INPUT  TYPE P DECIMALS 8,

      WA_OUTPUT TYPE P DECIMALS 2.



WA_INPUT = '22222.123456'.


CALL FUNCTION 'ROUND'

     EXPORTING

          INPUT         = WA_INPUT

     IMPORTING

  OUTPUT = WA_OUTPUT

     EXCEPTIONS

          INPUT_INVALID = 1

          OVERFLOW      = 2

          TYPE_INVALID  = 3

          OTHERS        = 4.

Thanks &Regards,

Tashi

former_member202818
Active Contributor
0 Kudos
1,192

Hi Mishra,

Are you trying to limit the decimal places in ALV or Smartform?

Then you can use other techniques provided in ALV or Smartform.

ALV

  gwa_fcat-decimals_o = 2.


Smartform

&gwa-amount(.2)&

Regards

Sreekanth

0 Kudos
1,192

Hi Sreekanth,

Thanks for your reply. I want to use in smartform but after using (.2) value is coming in next line, tried many solutions but still its coming in next line. Can you help me how to resolve this issue?

Thanks,

Maithili.

0 Kudos
1,192

Hi Maithali,

Please use statement with Keyword Condense.

Example illustrated below:

CONDENSE string.

DATA: VAR(10) VALUE '    ABC  '.

CONDENSE  VAR.  "Removes SPACES both sides of a String.

WRITE: VAR.   "output = ABC

VAR = '   A   B   C '.

CONDENSE  VAR.  "Removes all SPACES of a String.

WRITE: VAR.   "output = ABC

Please validate the same at your end and act accordingly, please come back if any inputs are required.

BR/Thanks

Pranav Agrawal

0 Kudos
1,192

Use (.2C) instead of (.2)

0 Kudos
1,192

This message was moderated.

0 Kudos
1,192

Save the value as text in a global variable & then display it

Former Member
0 Kudos
1,192

Hi Maithili,

I would recommend to use this in an easiest form if you would like to proceed wit, the same is illustrated below:

Ex: Data : lv_amount type p decimals 2.

lv_amount = '231233.548'   .

Write lv_amount.   "AMOUNT will have 231233.55

lv_amount = '3342322.573'.

Write lv_amount. "AMOUNT will have 3342322.57

Please validate the same at your end as well, let me know in case you need any further inputs from my end.

BR/Thanks

Pranav Agrawal

atul_mohanty
Active Contributor
0 Kudos
1,192

Hi -

Use the function module ROUND as suggested by Tashi above.

0 Kudos
1,192

Hi,

Use Type cast method instead of finding FM.

DATA : i type p decimals 4 VALUE '57846.5379'.

DATA : j type p decimals 2.

j = i.

Write : / i.

Write : / j.


Regards,

Velmurugan B

Former Member
0 Kudos
1,192

Take a look at program DEMO_ROUND.

Also read documentation of Round function and example code.

While calling round function, you can pass dec parameter value as 2 for rounding to 2 decimal places.

Former Member
0 Kudos
1,192

thank you all.

Pragnesh_7se7
Participant
0 Kudos
1,192

Easiest way,

Declare variable with two decimal places and pass value to it,

If yo found answer, change the status of question.