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: 

Round off a decimal number

Former Member
0 Kudos

Dear All,

i need to round off a decimal to nearest integer.

ex:0.4 should be 0,0.5 should be 1.

Can you help me how to handle this

The followig code is giving error.

data: var1 type p decimals 2 vlaue '23.30.

var1 = round(var1) is not working..

Kindly help me how to handle this

Praveen

1 ACCEPTED SOLUTION

suresh_datti
Active Contributor
0 Kudos

Hi,

You can use the function module ROUND to round it up or down.

Regards,

Suresh Datti

12 REPLIES 12

suresh_datti
Active Contributor
0 Kudos

Hi,

You can use the function module ROUND to round it up or down.

Regards,

Suresh Datti

Former Member
0 Kudos

Hi Suresh,

Thanks for the reply,but the FM is expecting sign,but i want to do it for positive and negative values..

Is there any other way to do it?

Praveen

0 Kudos

Hi

Use this syntax rule to specify the number of decimal places in a number.

ROUND <valFRACTION>

The value is rounded off at the (<valFRACTION>1) th decimal place. If this number is >= 5, the value is rounded up. If it is < 5, the value is rounded down. The result is a number in which the (<valFRACTION>1)th and all subsequent decimal places are equal to 0. The other digits in the number may have been changed if the value was rounded up.

otherwise ise

ceil--->round up

trunc--->remove decimals

floor--->round down

regards

Former Member
0 Kudos

Hi ,

Can try CEIL(var1)

Hope it helps

Former Member
0 Kudos

write this coding.

data : v_int type i.

data : v_char(5) value '10.49'.

v_int = v_char.

write 😕 v_int.

output.

if v_char is 10.49 then v_int will be 10.

if v_char is 10.5 then v_int will be 11.

Award points if it helps.

0 Kudos

simply move it to a variable of type i as suggested by Srinivas Reddy .

It would also take care of both positive and negative values.

Regards

Raja

Former Member
0 Kudos

U can try this code sample

REPORT demo_data_function .

* numeric datatypes

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.
<b>n = floor( m ). WRITE: / 'FLOOR:', n.</b>
n = trunc( m ). WRITE: / 'TRUNC:', n.
n = frac( m ).  WRITE: / 'FRAC: ', n.

ULINE.

FLOOR will work. Just try it, if ur problem got solved kindly reward points and close the thread.

Former Member
0 Kudos

Hi Praveen,

You can try using this bit of code

data: var1 type p decimals 2 value '23.30'.

data: var2(2) type n.

WRITE:var1 decimals 0 to var2.

write var2.

var2 will have the rounded value of the number.

Hope this helps.

Thanks & Regards,

Yogeshwari Agashe

Former Member
0 Kudos

Hi,

Use

CEIL : Smallest integer value that is not less than x

FLOOR : Largest integer value that is not greater than x

data: var1 type p decimals 2 value '23.30'.

var1 = Ceil( var1 ) or var1 = floor( var1 )

Regards,

Digesh Panchal

Former Member
0 Kudos

hi Praveen,

checkout the link..,

hope it helps..,

regards,

Vinoth

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

This message was moderated.