PostgreSQL 18 reference · Math Functions
PostgreSQL ROUND() Function
Round a number to a given number of decimal places (0 by default). numeric rounds halves away from zero.
PostgreSQL 18
Syntax
round(x) | round(x numeric, places)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
places optional |
Decimal places; negative rounds to tens, hundreds…. Default: 0 |
Return value
A number of the input type.
Examples
SELECT round(2.5) AS a, round(-2.5) AS b, round(3.14159, 2) AS c, round(1234.5, -2) AS d;
Output
a | b | c | d ---+----+------+------ 3 | -3 | 3.14 | 1200 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT round(2.5::double precision) AS float_half, round(2.5::numeric) AS numeric_half;
Output
float_half | numeric_half
------------+--------------
2 | 3
(1 row)Run this on your computer — see “Get Started” for setup.
round(x, places) only exists for numeric, so cast floating-point values first:
round(avg(price)::numeric, 2).
In other languages
ROUND()· SQLite
Related
TRUNC()· Truncate a number toward zero, optionally keeping some decimal places: trunc(2.789, 2) is 2.78.CEIL()· Round a number up to the nearest integer: ceil(2.1) is 3 and ceil(-2.1) is -2. ceiling() is a synonym.FLOOR()· Round a number down to the nearest integer: floor(2.9) is 2 and floor(-2.1) is -3.TO_CHAR()· Format a date, timestamp or number as text with a pattern such as 'DD Mon YYYY' or 'FM999,990.00'.- SQL Aggregate Functions · tutorial