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

ceil calculation is wrong

Former Member
0 Likes
1,163

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

1 ACCEPTED SOLUTION
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,086

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

7 REPLIES 7
Read only

Former Member
0 Likes
1,086

Hi,

Try using TRUNC



w_no_of_cases_temp = TRUNC( vbdpr-fkimg *
( marm-umren / marm-umrez ) ).

Regards,

Vikranth

Read only

0 Likes
1,086

Hi Vikranth

If i use this formula the deciaml places is displaying. I dont want decimai places.

Pls help me

Read only

0 Likes
1,086

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

Read only

Former Member
0 Likes
1,086

hi kumar,

how will "*204000 * 1 / 6000* ." become 35???? its 34

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,087

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

Read only

0 Likes
1,086

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

Read only

Former Member
0 Likes
1,086

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