Skip to Content
Former Member

### Commercial rounding to the closest integer number

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

##### Add comment
10|10000 characters needed characters exceeded

### 5 Answers

• Former Member
Feb 25, 2009 at 10:21 AM

Hi,

Try assigning your variable to below declared variable.

DATA: gv_var type p length 2 decimals 3.

Thanks,

Srilakshmi.

##### Add comment
10|10000 characters needed characters exceeded
• Feb 25, 2009 at 10:20 AM

Use ROUND function module

##### Add comment
10|10000 characters needed characters exceeded
• Former Member Former Member

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.

• Former Member
Feb 25, 2009 at 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

##### Add comment
10|10000 characters needed characters exceeded
• Dec 24, 2014 at 11:54 AM

Use function ROUND.

e.g. result = round( val = '21.490' dec = 0 )

##### Add comment
10|10000 characters needed characters exceeded
• Dec 24, 2014 at 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.

##### Add comment
10|10000 characters needed characters exceeded