How Round() Works in SQLite

In SQLite, the round() function allows you to round numbers up or down to a given decimal place.

It returns a floating-point value from the first argument, with the number of decimal places that you specify in the (optional) second argument.

If you don’t provide the second argument, it’s assumed to be 0.

Syntax

You can use round() with either one or two arguments:

round(X)
round(X,Y)
  • X is the value to be rounded
  • Y is optional. It’s the number of decimal places for which to round X.

Examples

Here’s a simple example to demonstrate.

SELECT round(7.50);

Result:

8.0

In this case, the value was rounded up. But this could also be rounded down, depending on the value.

SELECT round(7.49);

Result:

7.0

Specify Decimal Places

You can add a second argument to determine how many decimal places are included in the result.

SELECT round(7.51, 1);

Result:

7.5

This can also affect how the value is rounded.

SELECT 
  round(7.549, 0),
  round(7.549, 1),
  round(7.549, 2);

Result:

round(7.549, 0)  round(7.549, 1)  round(7.549, 2)
---------------  ---------------  ---------------
8.0              7.5              7.55           

Here’s an example with more decimal places.

SELECT 
  round(.12345678, 5),
  round(.12345678, 6),
  round(.12345678, 7);

Result:

round(.12345678, 5)  round(.12345678, 6)  round(.12345678, 7)
-------------------  -------------------  -------------------
0.12346              0.123457             0.1234568