Getting the ceil value of a number in SQLite

wrongusername picture wrongusername · Feb 19, 2013 · Viewed 9k times · Source

So I see this question has a good answer, but I want to round up no matter what, instead of rounding down no matter what. Adding 1 to it before casting int wouldn't work because it would "round" 5.0 into 6.0, for example.

So how should I implement ceil in SQLite?

Answer

Gordon Linoff picture Gordon Linoff · Feb 20, 2013

How about this?

select (case when x = cast(x as int) then cast(x as int)
             else 1 + cast(x as int)
        end)