views:

126

answers:

2

With MySQL

a DIV b

is much faster than

FLOOR(a / b).

But I need to round up so I'm using,

CEIL(a / b)

It seems strange that there wouldn't be a ceiling version of DIV, but I can't find it. Is there anything undocumented hidden away somewhere? Or any other non floating point way to do this?

+2  A: 

For a > 0 you can write

(a - 1) div b + 1
Gleb
Be careful - what happens if a is 0?
finnw
Thanks, actually (a + b - 1) DIV b would be better I guess.
Gleb
+3  A: 

Alternative:

(a + b - 1) DIV b

finnw