02-25-2009 10:18 AM
Hi,
I have a requirement to convert the Menge(quantity) to the nearest integer number by rounding off.
For example 21.490 becomes 21.000 while 21.510 becomes 22.000.
I checked for Floor, Ceil statements but these are not solving my purpose as they give next lowest or highest value.
I need to convert it as per my example. At run time it should check first place after decimal and then should convert it accordingly.
Please help if any pointers available.
Thanks in advance.
Swati
02-25-2009 10:20 AM
02-25-2009 10:28 AM
Please let me know what parameters should i pass?
I tried with following values:
decimal = '1'
input = '21.490'
sign = 'X'.
decimal = '.490'
input = '21'
sign = '+'
No output. Message is "Please use a number field for the input value"
02-25-2009 10:34 AM
02-25-2009 10:37 AM
DATA: v_int TYPE int4 VALUE '73882'.
DATA: v_mod TYPE int4.
DO.
v_mod = v_int MOD 1000.
IF v_mod = 0.
EXIT.
ENDIF.
v_int = v_int + 1.
ENDDO.
WRITE: / v_int.
" It will show 74000 for the input 73882..
" change the input and see the results..
10-12-2011 10:38 AM
Sorry for replying to an old post, but I too faced the same issue.
I used first the CEIL function to get the ceiling value. From this value, I subtracted the original value and checked the difference. If it is less then 0.5 then I used the FLOOR function and if it is more than 0.5 then I used the CEIL function.
10-12-2011 11:52 AM
Hi ,
we were facing the same problem while developing ABAP-HR reports
u can adjust or modify your code according to this i have used dec_part very helpfull
data:dec_part type p decimals 4,
num1 type PA0014-BETRG,
num2 TYPE PA0014-BETRG,
num TYPE string.
num = '21.490'.
break-point.
if num = '21.490'.
dec_part = frac( num ).
if dec_part >= '0.500'.
num1 = ceil( num ).
else.
num1 = FLOOR( num ).
endif.
endif.
num = '21.510'.
if num = '21.510'.
dec_part = frac( num ).
if dec_part >= '0.500'.
num2 = ceil( num ).
else.
num2 = FLOOR( num ).
endif.
endif.
02-25-2009 10:21 AM
Hi,
Try assigning your variable to below declared variable.
DATA: gv_var type p length 2 decimals 3.
Thanks,
Srilakshmi.
02-25-2009 12:39 PM
split number at '.' into lv_num1 lv_num2
if lv_num2 + 0(1) < = 4
concatenate lv_num1 '.' '000' into lv_num1.
else
lv_num1 = lv_num1 + 1.
concatenate lv_num1 '.' '000' into lv_num1.
Edited by: BrightSide on Feb 25, 2009 12:39 PM
12-24-2014 11:54 AM
12-24-2014 12:17 PM
Hi,
Do it on very simple way.
Data: Int type I,
val type (your values data type ).
int = your values variable [21.490].
int = 21. [not require to write in code, just for information ]
val = int . [21.000 , final value].
Regards.
Praveer.