 Former Member

# How to calculate upper limit of variable ?

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

10|10000 characters needed characters exceeded

### Related questions Former Member
Posted on Mar 25, 2008 at 10:59 AM

Hi,

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

10|10000 characters needed characters exceeded
• Former Member
Posted on Mar 25, 2008 at 10:20 AM

hi,

Use ROUND FM ..

Regards,

Santosh

10|10000 characters needed characters exceeded
• Former Member
Posted on Mar 25, 2008 at 10:23 AM

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-

Shiva

10|10000 characters needed characters exceeded
• Former Member Former Member

Hi,

well the best way is to use CEIL and FLOOR commands.

```
IF variable LE 5.0005.

variable = FLOOR(variable).

ENDIF.

IF variable GT 5.0005 AND variable LT 6.000.

variable = CEIL(variable).

ENDIF.

```

Regards.

• Former Member
Posted on Mar 25, 2008 at 10:29 AM

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.

10|10000 characters needed characters exceeded
• Former Member
Posted on Mar 25, 2008 at 10:39 AM

Hi,

Try using FM ROUND.

Thanks,

Sriram Ponna.