SQLite 3 reference · Math Functions
SQLite ROUND() Function
Round a number to a given number of decimal places (0 by default). Halves round away from zero.
SQLite 3
Syntax
round(X, Y)
Parameters
| Parameter | Description |
|---|---|
X |
A number (text that looks like a number is converted). |
Y optional |
Decimal places to keep. Default: 0 |
Return value
A floating-point number, or NULL.
Examples
SELECT round(2.5) AS a, round(-2.5) AS b, round(3.14159, 2) AS c;
Output
a | b | c 3 | -3 | 3.14
SELECT round(avg(price), 2) AS avg_price
FROM products;
Output
avg_price 69.57
round() always returns a floating-point value. To get an integer, use CAST(round(x) AS INTEGER). To show
exactly two decimals as text (2.50 rather than 2.5), use format('%.2f', x).
In other languages
ROUND()· PostgreSQL
Related
CEIL()· Return the smallest integer value not less than a number, rounding up: ceil(2.1) is 3. ceiling() is a synonym.FLOOR()· Return the largest integer value not greater than a number, rounding down: floor(2.9) is 2 and floor(-2.1) is -3.TRUNC()· Drop the fractional part of a number, rounding toward zero: trunc(2.7) is 2 and trunc(-2.7) is -2.FORMAT()· Build a string from a template with printf-style placeholders such as %s, %d, %.2f and %,d. printf() is the old name.- SQL Aggregate Functions · tutorial