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 for rounding off a decimal value

former_member195383
Active Contributor
0 Kudos

Hi All,

Is there any FM to round off a decimal value. Like converting 25.01 to 25 .

I was checking the FM HR_TH_ROUND_AMOUNT_DIRECT .

It asks for a parameter Rounding Rule. Can any one guide me so as to

find this Rounding Rule.

Kindly let me know any other FM name reg: the same.

Regards

Rudra

10 REPLIES 10

Former Member
0 Kudos

Rudra,

Use ABS ROUNDINGfunctionS

Ex:

wa_output-absqy = ABS( wa_iseg-buchm - wa_iseg-menge )

Manas Mishra

Edited by: Kumar Manas Mishra on Jan 29, 2010 11:03 AM

Edited by: Kumar Manas Mishra on Jan 29, 2010 11:07 AM

0 Kudos

Hello

Use ABS function

Manas, are you sure ?

Not TRUNC ?

0 Kudos

Hey Dzed,

I propose the FM: ROUND

Cheers,

Suhas

0 Kudos

What is the harm in ABS

DATA:NUM TYPE P VALUE '12.01',
                     NUM2 TYPE P.

 NUM2 = ABS( NUM ).
 WRITE: NUM2.

Manas M.

0 Kudos

Hello

Nothing

Try this code:


DATA:NUM TYPE P VALUE '12.01'.
WRITE: NUM.

It is your code but little changed

0 Kudos

Ohh...Really Intresting. Good Learning.

As Rudra needed some functions i suggested him ABS , ROUND functions or else there are many alternative solutions.

Manas M.

Former Member
0 Kudos

Hi,

You do not need a FM. Check [round, rescale - Rounding Functions |http://help.sap.com/abapdocu_70/en/ABENDEC_FLOATING_POINT_FUNCTIONS.htm] and [WRITE - ROUND addition|http://help.sap.com/abapdocu_70/en/ABAPWRITE_TO_OPTIONS.htm#!ABAP_ADDITION_8@8@]

Regards,

Adrian

Former Member
0 Kudos

Hello,

If you are looking for 0.5 rounding, you can round off a value directly by assigning it to a variable of type i and no need of a FM.


data: var1 type p decimals 2,
      var2 type i.

var1 = '25.01'.

var2 = var1.

write: var2

Vikranth.

Former Member
0 Kudos

Hi rudra,

although ur prob is solved. but i found it advisable to share this.

if u want to round off any value, assign that value to ' type i' type variable.

u will get ur value rounded off.

i.g.


data : var1 type p value '25.01',
       var2 type i.

var2 = var1.
write :  var2.

Regards,

maverick

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