So you think you can count
Round and other functions
18. Other rounding functions
Revision and practice


That was correct again. There are also other rounding functions available in each database.

  • ceil(x) (in SQL Server - ceiling()) returns the smallest integer which is not less than x. In other words, it always rounds up (13.7 will become 14, and so will 13.1).
  • floor(x) is the opposite of ceil(x) – it always rounds down, so 13.7 will become 13.
  • trunc(x) (in MySQL - truncate()) is yet another function which always rounds towards 0. For positive numbers, it works like floor(x) (13.7 becomes 13). For negative ones, it works like ceil(x) (-13.7 becomes -13).

What's more, each of the functions above can be used with a second argument to specify its precision, as in the case of round(x,precision).

As with the function round, in PostgreSQL the first argument of the rounding functions has to be of type numeric. Use casting when appropriate.

Now you really understand that there are various approaches to rounding!


Let's check a few rounding functions in the next few exercises. Show the character's name together with its weight, followed by the weight rounded up.

Stuck? Here's a hint!

Use ceil(weight).


Code editor