02-07-2006 10:55 AM
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
02-07-2006 10:57 AM
Hi,
You can use the function module ROUND to round it up or down.
Regards,
Suresh Datti
02-07-2006 10:57 AM
Hi,
You can use the function module ROUND to round it up or down.
Regards,
Suresh Datti
02-07-2006 11:09 AM
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
02-07-2006 11:16 AM
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
02-07-2006 11:09 AM
02-07-2006 11:13 AM
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.
02-07-2006 11:18 AM
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
02-07-2006 11:15 AM
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.
02-07-2006 11:18 AM
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
02-07-2006 11:20 AM
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
02-07-2006 11:20 AM
09-06-2013 9:56 AM
05-10-2016 11:22 AM