‎2009 Aug 31 10:15 AM
Hi
I am using below formula to calculate no of cases
w_no_of_cases_temp = CEIL( vbdpr-fkimg *
( marm-umren / marm-umrez ) ).
input value is
vbdpr-fkimg = 204000
marm-umren = 1
marm-umrez = 6000
output is 35. But it should be 34.
i checke few cases. Output is correct. Above itme oly i am getting wrong output. Kindly help me
‎2009 Aug 31 11:34 AM
data:w_no_of_cases_temp type p.
w_no_of_cases_temp = ( 204000 * ( 1 / 6000 ) ). "=34
write w_no_of_cases_temp.
w_no_of_cases_temp = CEIL( 204000 * ( 1 / 6000 ) )."=35
write w_no_of_cases_temp.
w_no_of_cases_temp = FLOOR( 204000 * ( 1 / 6000 ) )."=34
write w_no_of_cases_temp.
Why CEIL ???
‎2009 Aug 31 10:17 AM
Hi,
Try using TRUNC
w_no_of_cases_temp = TRUNC( vbdpr-fkimg *
( marm-umren / marm-umrez ) ).
Regards,
Vikranth
‎2009 Aug 31 11:06 AM
Hi Vikranth
If i use this formula the deciaml places is displaying. I dont want decimai places.
Pls help me
‎2009 Aug 31 11:15 AM
Hi Kumar,
What is the type of the variable w_no_of_cases_temp ? Try declaring it as type p and check.
data: w_no_of_cases_temp type p.
w_no_of_cases_temp = TRUNC( vbdpr-fkimg *
( marm-umren / marm-umrez ) ).
Regards,
Vikranth
‎2009 Aug 31 11:25 AM
hi kumar,
how will "*204000 * 1 / 6000* ." become 35???? its 34
‎2009 Aug 31 11:34 AM
data:w_no_of_cases_temp type p.
w_no_of_cases_temp = ( 204000 * ( 1 / 6000 ) ). "=34
write w_no_of_cases_temp.
w_no_of_cases_temp = CEIL( 204000 * ( 1 / 6000 ) )."=35
write w_no_of_cases_temp.
w_no_of_cases_temp = FLOOR( 204000 * ( 1 / 6000 ) )."=34
write w_no_of_cases_temp.
Why CEIL ???
‎2009 Aug 31 11:52 AM
Hi,
how does CEIL work.... ?
After the decimal even if there is a single digit without 0 then it adds 1 to the result....
now taking your scenario...
CEIL( 204000 * ( 1 / 6000 ) ).
firstly the inner braces are calculated but they are not ceiled because CEIL is to be applied for the final result according to the statement above....
now, 1 / 6000 is calculated and the output is 0.000166... goes on... or you can say 1.666666667e-4
since floating point numbers supports till certain numbers so this number becomes
0.000167
now when you calculate 0.000167 * 204000
the result is 34.068
now if CEIL is applied to this result..... it converts the number 34.068 to 35
if you want to cross check you can also use this statement
CEIL(24 * ( 1 / 6 ) ).
this will result in the value 5 whereas it is 4.
So for this case you will have to modify your logic a bit for you not to get this inappropriate results....
instead of using CEIL or any others functions
declare an integer variable
This is how it works....
DATA w_int TYPE i.
w_int = w_no_of_cases_temp.
write w_int.
*this should resolve your issue......Regards,
Siddarth
Regards,
Siddarth
‎2009 Aug 31 11:47 AM
hi
read this
command result
ABS Absolute value of argument
CEIL Smallest integer value
FLOOR Largest integer value
TRUNC Integer part of argument
FRAC Fraction part of argument
now use as per your requirement