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: 

Rounding-off Currency fields.

former_member723628
Active Participant
0 Kudos

Hi,

Can someone tell me how to round-off value of currency field.

If fraction <= 0.49 it should be rounded-off to 0.00

If fraction >= 0.50 it should be rounded-off to 1.00

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Try this...



report zrich_0002 .


data: curr1 type p decimals 2 value '.49',
      dec type p decimals 2 .


dec = frac( curr1 ).
if dec <= '.49'.
  curr1 = floor( curr1 ).
else.
  curr1 = ceil( curr1 ).
endif.


check sy-subrc  = 0.

Regards,

Rich Heilman

8 REPLIES 8

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Try this...



report zrich_0002 .


data: curr1 type p decimals 2 value '.49',
      dec type p decimals 2 .


dec = frac( curr1 ).
if dec <= '.49'.
  curr1 = floor( curr1 ).
else.
  curr1 = ceil( curr1 ).
endif.


check sy-subrc  = 0.

Regards,

Rich Heilman

Former Member
0 Kudos

parameter p(4) type P decimals 2.

data wa(4) type P decimals 0.

data wa1(4) type P decimals 2.

wa = p .

wa1 = wa .

write wa1.

Cheers.

Former Member
0 Kudos

Just move it to a integer field.

0 Kudos

If any of these answers have helped you, please remember to award points accordingly and mark this post as solved. Thanks.

Regards,

Rich HEilman

0 Kudos

Thanks a lot Rich. This has solved my problem

Regards,

Gajendra Bhatt

Former Member
0 Kudos

Hi, you have the Function Module ROUND too,

here a litle example ( the paremeter sign = 'X' set how the number will be rounded )

DATA l_input TYPE p DECIMALS 5.

break-point.

l_input = '0.499'.

CALL FUNCTION 'ROUND'

EXPORTING

decimals = 0

input = l_input

sign = 'X'

IMPORTING

output = l_input

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

l_input = '0.500'.

CALL FUNCTION 'ROUND'

EXPORTING

decimals = 0

input = l_input

sign = 'X'

IMPORTING

output = l_input

EXCEPTIONS

input_invalid = 1

overflow = 2

type_invalid = 3

OTHERS = 4.

Saludos

Daniel

0 Kudos

Hi Daniel,

Function Module ROUND doesn't return any values in the output field.

Regards,

Gajendra Bhatt

0 Kudos

Gajendra

Check again it is working properly.

regards

Siddarth