01-29-2010 10:00 AM
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
01-29-2010 10:02 AM
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
01-29-2010 10:09 AM
01-29-2010 10:15 AM
01-29-2010 10:20 AM
What is the harm in ABS
DATA:NUM TYPE P VALUE '12.01',
NUM2 TYPE P.
NUM2 = ABS( NUM ).
WRITE: NUM2.
Manas M.
01-29-2010 10:30 AM
Hello
Nothing
Try this code:
DATA:NUM TYPE P VALUE '12.01'.
WRITE: NUM.
It is your code but little changed
01-29-2010 10:35 AM
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.
01-29-2010 10:06 AM
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
01-29-2010 10:07 AM
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.
04-26-2010 8:38 AM
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
05-10-2016 11:48 AM
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