cancel
Showing results for 
Search instead for 
Did you mean: 

need fn module for rounding off decimals

Former Member
0 Kudos

hi ,

i have the requirement to find out the fn module to round off the third decimal value.for eg..if the value is 155.123 then it should print 155.10 and if the value is 155.126 then it should print 155.13.is there any fn module availabel for this type of rounding...

thnax in advance...

Praveen.Nekkanti

Accepted Solutions (0)

Answers (5)

Answers (5)

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

Former Member
0 Kudos

Hi Praveen,

If the conversion logic you want to implement is within a loop:

Use Simple SAP arithmethic function <b>CEIL</b> this will round of the value to the next upper value or use <b>FLOOR</b> to the lower value.

If the conversion logic you want to implement is outside a loop use the FM mentioned in the post above.

Just for better performance

Cheers

VJ

Former Member
0 Kudos

Hi,

chk whether this FM works for u:

HR_NZ_ROUNDING_DECIMALS

rgds,

Latheesh

Former Member
0 Kudos

Please try this FM HR_NL_ROUNDING.

DATA: WA_VALUE1 TYPE P05_DEC15_4,

WA_VALUE2 TYPE MAXBT.

MOVE '1234.567' TO WA_VALUE1.

CALL FUNCTION 'HR_NL_ROUNDING'

EXPORTING

INPUT = WA_VALUE1

METHOD = '2'

IMPORTING

OUTPUT = WA_VALUE2.

Former Member
0 Kudos

Hello Praveen,

Use function module ROUND.

Regards,

Tanveer.

Please mark helpful answers

Former Member
0 Kudos

Hi Naveen,

You can use ROUND function Module to satisfy your requirement.

Just check this code.

REPORT ZTEST_SHAIL4 .

data: out type p decimals 2,

inp type f.

inp = '123.324'.

CALL FUNCTION 'ROUND'

EXPORTING

  • DECIMALS =

input = inp

  • SIGN = ' '

IMPORTING

OUTPUT = out

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 out.

The output will be 123.32.

Reward points if found useful.

Regards,

SP.