round(numeric, integer) — Round to a number of decimal places
Last updated: 2026-11-04
round(numeric, integer) — Round to a number of decimal places
round() rounds a value to the given number of decimal places, or to a whole number when the second argument is omitted. Combined with numeric it is exact decimal arithmetic with none of the binary floating-point representation error; applied to double precision it instead uses banker's rounding, so a .5 rounds to the nearest even number.
| Kind | function |
|---|---|
| Example Language | SQL |
📝 Syntax
round(value numeric, scale integer) → numeric
round(value double precision) → double precision
⚙️ Parameters
| value numeric | The value to round. Type numeric or double precision. |
|---|---|
| scale integer | How many decimal places to keep; when omitted it is treated as 0, i.e. rounding to a whole number. Type integer. |
Returns:numeric — the rounded value; a numeric input returns numeric and a double precision input returns double precision.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | price | round_2 | round_0
----+---------+---------+---------
1 | 19.9950 | 20.00 | 20
2 | 2.3450 | 2.35 | 2
3 | 2.5000 | 2.50 | 3
(3 rows)
📌 Key Points
- numeric rounds half away from zero: round(2.5) gives 3 and round(-2.5) gives -3.
- double precision rounds half to even: round(2.5::float8) gives 2 and round(3.5::float8) gives 4.
- Keep money in numeric end to end so that double precision does not accumulate representation error.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QIs round(2.5) 2 or 3?
AIt depends on the type: numeric gives 3 (half away from zero) while double precision gives 2 (half to even). For money, cast explicitly to numeric.