SQLite Round() Function

The SQLite ROUND() function returns a floating-point value that represents value rounded to a specified length or precision.

Syntax

ROUND(value,precision)Code language: SQL (Structured Query Language) (sql)

Arguments

The ROUND() function accepts two arguments.

value

The value is the floating-point value or an expression that evaluates to a floating-point value.

precision

The precision is a positive integer. The value is rounded to its closest representation, not towards zero.

If either value or precision is NULL, the ROUND() function returns NULL. If you omit the precision argument, it is assumed to be zero. This will result in a whole number although the result is still a floating-point value.

Return Type

Real

Examples

The following statement uses the ROUND() function to round a floating-point value to 2 decimals:

SELECT ROUND(1929.236, 2);Code language: SQL (Structured Query Language) (sql)
ROUND(1929.236,2)
-----------------
1929.24Code language: CSS (css)

The following statement rounds the number 1929.236 to a value with 1 decimal point.

SELECT ROUND(1929.236, 1);Code language: SQL (Structured Query Language) (sql)
ROUND(1929.236, 1)
------------------
1929.2Code language: CSS (css)

The following statement uses the ROUND() function without specifying the precision argument.

SELECT ROUND(1929.236);Code language: SQL (Structured Query Language) (sql)
ROUND(1929.236)
---------------
1929Code language: CSS (css)

This example uses the ROUND() function to round the number 0.5:

SELECT ROUND(0.5);Code language: SQL (Structured Query Language) (sql)

The output is:

ROUND(0.5)
----------
         1Code language: CSS (css)
Was this tutorial helpful ?