Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Commercial rounding to the closest integer number

Former Member
0 Kudos

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

10 REPLIES 10

GauthamV
Active Contributor
0 Kudos

Use ROUND function module

Former Member
0 Kudos

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"

Former Member
0 Kudos

Hi,

Try CEIL or FLOOR Functions.

Thanks,

Prashanth

Former Member
0 Kudos

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..

Former Member
0 Kudos

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.

Former Member
0 Kudos

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
0 Kudos

Hi,

Try assigning your variable to below declared variable.

DATA: gv_var type p length 2 decimals 3.

Thanks,

Srilakshmi.

Former Member
0 Kudos

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

Former Member
0 Kudos

Use function ROUND.

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


ipravir
Active Contributor
0 Kudos

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.