Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
prma7799
Master III
Master III

Ceil and Floor functions

Hi Experts,

Can anybody explain me how the Ceil and Floor function will work and how the below output is come .

e.g

Ceil:

ceil( 1.1 , 1 , 0.5 ) returns 1.5

Ceil(9.156,98) returns 98

Floor:

floor( 3.88 , 5 ) returns 0

floor( 1.1 , 1 , 0.5 ) returns 0.5

Thanks

Prashant

1 Solution

Accepted Solutions
saumyashah90
Specialist
Specialist


See

1)Both gives always a positive number always

2)Both gives rounding of base with offset

3)ceil/floor     (x[,base[,offset]])

a)when you have single number it is x

b)when you have two numbers it is x and offset

c)when you have three it is x,base,offset

Now think offset as + or - values on scale

so lets take your example

1)Ceil(1.1,1,0.5)

here 1 is base and 0.5 is offset.

so because it is ceil rounding will be done upwards   -0.5 ,0,0.5,1,1.5 so if you go 0.5 up from1 you will reach to 1.5

hence result is 1.5

and similarly for floor rounding of is done downwards it is 0.5

2)Ceil(9.156,98)

x=9.156 and 98 is the offset

when there are 2 numbers you get max of both in ceil if it goes above offset and 0 if it goes below 0 with offset in floor

hence 98 in ceil

and floor(3.88,5)

when you think on scale it will go below 0 hence floor of this is 0

View solution in original post

5 Replies
jyothish8807
Master II
Master II

Hi ,

Please go through this:

http://community.qlik.com/thread/79632

Regards

KC

Best Regards,
KC
amit_saini
Master III
Master III

Hi,

Ceil function will round up a number. Ex: ceil(3.4) will return 4.

Floor will round down a number. Ex: floor(3.4) will return 3.

Thanks,
AS

saumyashah90
Specialist
Specialist


See

1)Both gives always a positive number always

2)Both gives rounding of base with offset

3)ceil/floor     (x[,base[,offset]])

a)when you have single number it is x

b)when you have two numbers it is x and offset

c)when you have three it is x,base,offset

Now think offset as + or - values on scale

so lets take your example

1)Ceil(1.1,1,0.5)

here 1 is base and 0.5 is offset.

so because it is ceil rounding will be done upwards   -0.5 ,0,0.5,1,1.5 so if you go 0.5 up from1 you will reach to 1.5

hence result is 1.5

and similarly for floor rounding of is done downwards it is 0.5

2)Ceil(9.156,98)

x=9.156 and 98 is the offset

when there are 2 numbers you get max of both in ceil if it goes above offset and 0 if it goes below 0 with offset in floor

hence 98 in ceil

and floor(3.88,5)

when you think on scale it will go below 0 hence floor of this is 0

saumyashah90
Specialist
Specialist

if want to understand using multiple of base

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

Not applicable