‎2008 Feb 04 4:58 AM
If i have a value say, 1.47
the nearest integer value is 1.
if 1.51, the integer value is 2.
How to get this,
Thnx in advance
‎2008 Feb 04 5:02 AM
Hi
Check this code..
DATA l_f_kbetr4 type konp-kbetr .
CLEAR : l_f_kbetr4 , l_f_kbetr5 .
l_f_kbetr4 = l_F_kbetr1 - l_f_kbetr3 .
CHECK = FRAC( l_f_kbetr4 ) .
IF CHECK GE '0.50' .
l_f_kbetr4 = CEIL( l_f_kbetr4 ) .
ELSE .
l_f_kbetr4 = FLOOR( l_f_kbetr4 ) .
ENDIF.
l_f_kbetr5 = l_f_kbetr4 .
G_r_E1KONP-KBETR = l_f_kbetr5 .
Hope it helps.
Praveen
‎2008 Feb 04 5:01 AM
Hi
try this,
report zars no standard page heading
line-size 170
line-count 65(4).
data : int type i.
data : char(10) type c value '123'.
class cl_abap_container_utilities definition load.
call method cl_abap_container_utilities=>read_container_c
exporting
im_container = char
importing
ex_value = int
exceptions
illegal_parameter_type = 1
others = 2.
write : int.
Reward if helpful,
GAURAV J.
‎2008 Feb 04 5:02 AM
Hi
Check this code..
DATA l_f_kbetr4 type konp-kbetr .
CLEAR : l_f_kbetr4 , l_f_kbetr5 .
l_f_kbetr4 = l_F_kbetr1 - l_f_kbetr3 .
CHECK = FRAC( l_f_kbetr4 ) .
IF CHECK GE '0.50' .
l_f_kbetr4 = CEIL( l_f_kbetr4 ) .
ELSE .
l_f_kbetr4 = FLOOR( l_f_kbetr4 ) .
ENDIF.
l_f_kbetr5 = l_f_kbetr4 .
G_r_E1KONP-KBETR = l_f_kbetr5 .
Hope it helps.
Praveen
‎2008 Feb 04 5:02 AM
Hi,
Use ROUND function, Number is rounded up or down during conversion.
The different formats of ROUND are:
ROUND <r> : Type P fields are multiplied by 10**(-r) and then rounded.
Ex:
DATA pack TYPE p VALUE '123.456'
DECIMALS 3.
WRITE pack DECIMALS 2.
WRITE: / pack ROUND -2,
/ pack ROUND -1,
/ pack ROUND 1,
/ pack ROUND 2.
Output:
123,46
12.345,600
1.234,560
12,346
1,235
Thanks
Madhavi
‎2008 Feb 04 5:03 AM
Declare an integer variable and assign floating value to this integer value . You can get the rounded value.
eg.
if var1 is of type p and value '1.56',
data:
var2 type i.
var2 = var1.
now the value of var2 should be 2.
‎2008 Feb 04 5:11 AM
Keshu,
Use below Functionalities which ever required.
DATA N TYPE P DECIMALS 2.
DATA M TYPE P DECIMALS 2 VALUE '5.55'.
N = CEIL( M ). WRITE: / 'CEIL: ', N.
N = FLOOR( M ). WRITE: / 'FLOOR:', N.
N = TRUNC( M ). WRITE: / 'TRUNC:', N.
Don't forget to reward if useful..
‎2008 Feb 04 5:24 AM
this code will help you
data:
v_var1 type p length 3 decimals 2 value '1.47',
v_var2 type p length 3 decimals 2 value '1.56',
v_var3 type i.
v_var3 = v_var1.
write:/ v_var3.
v_var3 = v_var2.
write:/ v_var3.
‎2008 Feb 04 5:35 AM
here is the simple code ...
There is function module Round .
give how much decimal you want and use FM.
DATA hour TYPE p DECIMALS 3 VALUE '1.200'.
CALL FUNCTION 'ROUND'
EXPORTING
DECIMALS = 0
input = hour
SIGN = 'X'
IMPORTING
OUTPUT = hour
.
write hour.
output : 1.000