SQLite round() Function

The SQLite round() function rounds the given number to the specified number of decimal places and returns the result.

Syntax

Here is the syntax of the SQLite round() function:

round(x, d)

Parameters

x

Required. The number to round.

d

Optional. The number of decimal places to retain. The default is 0.

Return value

The SQLite round() function rounds the specified number to the specified number of decimal places.

  • If d is greater than or equal to the number of decimal places of x, the original number is returned.
  • If is d less than the number of decimal places of x, round the number of decimal places of x to d return.
  • If d is negative, d is treated as 0.
  • The round() function will return NULL if either parameter is NULL.

Examples

This example shows how to use round() the basic usage of the SQLite function:

SELECT
    round(123.179, 1),
    round(123.179, 2),
    round(123.179, 4),
    round(123.179, 0),
    round(123.179, -1),
    round(123.179, -2);
 round(123.179, 1) = 123.2
 round(123.179, 2) = 123.18
 round(123.179, 4) = 123.179
 round(123.179, 0) = 123.0
round(123.179, -1) = 123.0
round(123.179, -2) = 123.0