Application Development and Automation 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: 
Read only

Function Module Needed to Round the Nearest Number value

Former Member
0 Likes
6,086

Hi,

I need a Function Module to round the Number to nearest value.

e.g. Input = 4.017

Output = 4.02

Can you Please tell the Function Module ?

Regards,

Surjith

6 REPLIES 6
Read only

Former Member
0 Likes
2,022

Hi,

Do like this

data: v_dec1 type p deciamals 3 value '4.017',

v_dec2 type p decimals 2.

v_dec2 = v_dec1.

write: v_dec2.

If this doesn't work, try FM ROUND.

or try this

v_dec2 = ROUND( v_dec3 ).

WRITE v_dec2.

Regards,

Satish

Read only

Former Member
0 Likes
2,022

Hi,

You can use *Floor * statement.

Thanks,

Sriram POnna.

Read only

Former Member
0 Likes
2,022

Hi,

Declare a var like below

Data temp type p decimals 2.

move <ur input variable> to temp.

write temp.

it is automatically rounded off.......

Cheers,

Will.

Read only

Former Member
0 Likes
2,022

DATA : l_var(4) TYPE p  decimals 3.
DATA : l_var2(4) TYPE p  decimals 2.

l_var = '4.017'.

CALL FUNCTION 'ROUND'
  EXPORTING
   DECIMALS            = 3
   input               = l_var
 IMPORTING
   OUTPUT              = l_var2.
write : l_var2.
Read only

Former Member
0 Likes
2,022

Hi,

Please try this function module:

Try the function ROUND.

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Jan 31, 2008 12:31 PM

Read only

Former Member
0 Likes
2,022

Hi All

Use the below code and it is so simple

For 2 decimal places

data(lv_round) = round(  val = '5678.65800341' dec = 2  ).


lv_round will be 5678.66


data(lv_round) = round(  val = '5678.65300341' dec = 2  ).


lv_round will be 5678.65


For 5 decimals


data(lv_round) = round(  val = '5678.65800741' dec = 5 ).


lv_round will be 5678.65801


data(lv_round) = round(  val = '5678.65800341' dec = 5 ).


lv_round will be 5678.65800


Thanks,

Murugan