Hello Friends,
I want small logic here,
I have one variable like amt = 5.001.
If amount increses up to 5.005 then amt should be 5.000
i have created constant c_val = 0.005 also
if amount increses like 5.006 then amount should be 6.000
for example,
5.000 should be 5.000
5.001 should be 5.000
5.002 should be 5.000
5.003 should be 5.000
5.004 should be 5.000
5.005 should be 5.000
5.006 should be 6.000
5.007 should be 6.000
5.008 should be 6.000
5.009 should be 6.000
Note : i dont want to use CEIL fn.
points rewarded soon
Regards,
RH
Hi,
Please refer the below program..
Reward points if it is useful...
data: v_amt type p decimals 3 value '5.006',
v_frc type p decimals 3 .
CONSTANTS: c_val TYPE p DECIMALS 3 value '0.005'.
v_frc = frac( v_amt ).
if v_frc <= c_val.
v_amt = floor( v_amt ).
else.
v_amt = ceil( v_amt ).
endif.
write:/ v_amt.
Regards,
vijay
Hi
Use either ROUND or FLOOR to do so
DATA n TYPE p DECIMALS 2.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.
n = abs( m ). WRITE: 'ABS: ', n.
n = sign( m ). WRITE: / 'SIGN: ', n.
n = ceil( m ). WRITE: / 'CEIL: ', n.
n = floor( m ). WRITE: / 'FLOOR:', n.
n = trunc( m ). WRITE: / 'TRUNC:', n.
n = frac( m ). WRITE: / 'FRAC: ', n.
The output appears as follows:
ABS: 5.55
SIGN: 1.00-
CEIL: 5.00-
FLOOR: 6.00-
TRUNC: 5.00-
FRAC: 0.55-
regads
Shiva
Hi Ronny,
1. using integer concept and the c_val as you said,
we can use this kind of logic.
2. Just copy paste.
3. Note : N2 is the final output variable.
REPORT ABC.
DATA : NUMBER TYPE P DECIMALS 3.
DATA : C_VAL TYPE P DECIMALS 3.
DATA : INTEGER TYPE I.
DATA : N1 TYPE P DECIMALS 3.
DATA : N2 TYPE P DECIMALS 3.
*----
C_VAL = '0.005'.
NUMBER = '5.005'.
*----
INTEGER = NUMBER.
N1 = NUMBER - C_VAL.
IF N1 > INTEGER.
N2 = INTEGER + 1.
ELSE.
N2 = N1.
ENDIF.
WRITE :/ NUMBER.
WRITE :/ INTEGER.
WRITE :/ N1.
WRITE :/ N2.
regards,
amit m.
Add a comment