Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Doubts in understanding the ceil and floor functions

Hi to all,

From qlikview help i knew how the ceil and floor functions works,but still i have some doubts in these two functions.

Ex1.ceil( 1.1 , 1 , 0.5 ) returns 1.5

ex2.Ceil(2.6, 0.25) returns 2.75

internally how ceil() works in above 2 examples

ex1.floor( 3.88 , 5 ) returns 0
ex2.floor( 1.1 , 1 , 0.5 ) returns 0.5
ex3.Floor(2.6, 0.25) returns 2.5

Internally how floor() works in above 3 examples.

Prior to this posting i had searched in the google,qlikview reference manual and in the book qlikview 11 for developers.But i didn't get any thing.

Can any one please helpme in the layman language as early as possible.

Thanks in advance.

1 Solution

Accepted Solutions
nagaiank
Specialist III
Specialist III

ceil(x [ , base [ , offset ]])

Rounding of x upwards to the nearest multiple of base with an offset of offset. The result is a number.

Examples:

ceil( 1.1 , 1 , 0.5 ) returns 1.5

Multiples of 1 are 0, 1, 2, 3, 4

If apply the offset 0.5, you get 0.5, 1.5, 2.5, 3.5, 4.5

The nearest higher number for 1.1 is 1.5 and so  ceil returns 1.5

floor(x [ , base [ , offset ]])

Rounding of x downwards to the nearest multiple of base with an offset of offset. The result is a number.

Examples:

floor( 3.88 , 5 ) returns 0

multiple of 5 are 0,5,10,15

In this list, the nearest lower number for 3.88 is 0 and so floor() returns 0

Hope this helps.

View solution in original post

9 Replies
nagaiank
Specialist III
Specialist III

ceil(x [ , base [ , offset ]])

Rounding of x upwards to the nearest multiple of base with an offset of offset. The result is a number.

Examples:

ceil( 1.1 , 1 , 0.5 ) returns 1.5

Multiples of 1 are 0, 1, 2, 3, 4

If apply the offset 0.5, you get 0.5, 1.5, 2.5, 3.5, 4.5

The nearest higher number for 1.1 is 1.5 and so  ceil returns 1.5

floor(x [ , base [ , offset ]])

Rounding of x downwards to the nearest multiple of base with an offset of offset. The result is a number.

Examples:

floor( 3.88 , 5 ) returns 0

multiple of 5 are 0,5,10,15

In this list, the nearest lower number for 3.88 is 0 and so floor() returns 0

Hope this helps.

swuehl
MVP
MVP

floor(), ceil() [and not to forget round()] all have the same possible arguments:

ceil(x [ , base [ , offset ]])

Rounding of x upwards to the nearest multiple of base with an offset of offset. The result is a number.

floor(x [ , base [ , offset ]])

Rounding of x downwards to the nearest multiple of base with an offset of offset. The result is a number.

round( x [ , base [ , offset ]])

Rounding of x upwards or downwards to the nearest multiple of base with an offset of offset. The result is a number. If x is exactly in the middle of an interval, it is rounded upwards.

'x' is your input number. 'offset' is the number your intervals start from. base is the interval increment.

So ex2.floor( 1.1 , 1 , 0.5 ) creates intervals like [0.5, 1.5]; [1.5, 2.5]; [2.5, 3.5] ...

If your input is 1.1, the first interval is the matching one. floor() now returns the lower limit and ceil() the upper limit of the matching interval.

Hope this helps,

Stefan

Joaquin_Lazaro
Partner - Specialist II
Partner - Specialist II

Hi:

Good help from krishnamoorthy & swuehl .

... but with QV 11 SR2 64-bits there is a problem with Round and Floor, both not working as expected.

See Support cases 00170986 & 00170987.

I could write a little trick but of course have other problems behind!!!

Not applicable
Author

Hi ,

  let x=ceil(5.3,2,8);

   As per your logic ,

Multiples of 2 are 0,2,4,6,8

If apply the offset 8 you get 8,10,12....

output will be 8 .

But i'm getting 6. Do you know why ? Am i missing anything ??

Thanks and Regards

Satti 

swuehl
MVP
MVP

The intervals are not only created by using positive integral numbers as factor for the increments, but also negative. So intervals start not only from 0,2,4,6,8,... but from ...-4, -2,0,2,4,6 ....

So 6 is indeed the nearest interval upper limit to 5.3.

Not applicable
Author

Thanks and Perfect ..

Akbar
Contributor II
Contributor II

thanks for this post

Vijayqlik4171
Contributor III
Contributor III

ceil(5.3,2,8) = 6

sloution 

intially =0

0,2,6,8 

your value is 5.3  

ceil will take nearest up value that is 6 

Vijayqlik4171
Contributor III
Contributor III

one more example detail

ceil(5.3,6,3)

5.3= input

6= increment (increment start with"0")

3= base

solution = 0(increment )+3(base)=3,  6(increment ) +3(base)=9,  12(increment )+3(base)=15

final input =5.3  

nearest for 5.3 = 9