# ROUND() in SQL (PostgreSQL and SQLite)

Source: https://sqlstreak.com/sql/functions/round · Tested on PostgreSQL 18.6 and SQLite 3.54.1; results generated 2026-11-22.


**Short answer:** `ROUND(x, n)` rounds `x` to `n` decimal places (to a whole number without `n`): `ROUND(13.456, 2)` is 13.46. Both databases round halves away from zero for ordinary values; they differ on negative `n` and on which types PostgreSQL accepts.

## Syntax

- PostgreSQL: `ROUND(numeric [, digits])  /  ROUND(double precision)` (Yes (with digits only for numeric))
- SQLite: `ROUND(x [, digits])` (Yes)

## Examples

### Average age, one decimal

```sql
SELECT species, ROUND(AVG(age), 1) AS avg_age
FROM pets
GROUP BY species
ORDER BY species;
```

Result (both engines):

| species | avg_age |
| --- | --- |
| bird | 4 |
| cat | 4.9 |
| dog | 5.1 |
| rabbit | 2 |

### A percentage

```sql
SELECT device, COUNT(*) AS plays,
       ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM plays), 1) AS pct
FROM plays
GROUP BY device
ORDER BY plays DESC;
```

Result (both engines):

| device | plays | pct |
| --- | --- | --- |
| mobile | 1449 | 60.2 |
| desktop | 733 | 30.5 |
| tv | 225 | 9.3 |

### Money to two places

```sql
SELECT m.name, ROUND(SUM(oi.quantity * m.price * 1.08), 2) AS with_tax
FROM order_items oi
JOIN menu_items m ON m.id = oi.item_id
GROUP BY m.name
ORDER BY with_tax DESC
LIMIT 5;
```

Result (both engines):

| name | with_tax |
| --- | --- |
| Pepperoni Rocket | 102.06 |
| Four Cheese Orbit | 75.6 |
| BBQ Meteor | 66.96 |
| Margherita | 59.4 |
| Veggie Nebula | 42.12 |

## Edge cases, measured on both engines

| Case | PostgreSQL | SQLite |
| --- | --- | --- |
| Two decimals | 13.46 | 13.46 |
| A half | 3 | 3 |
| A negative half | -3 | -3 |
| A tricky decimal | 2.68 | 2.67 |
| Negative digits | 1200 | 1235 |
| Integer division first | 3 | 3 |
| A double precision value with digits | error: function round(double precision, integer) does not exist | 2.5 |
| NULL | NULL | NULL |

## Common mistakes

- `ROUND(x::float, 2)` in PostgreSQL: there's no ROUND(double precision, integer). Cast to numeric instead (see the matrix and the error page).
- Rounding an integer division: `ROUND(7 / 2)` is 3 because the division already threw the half away. Write 7.0 / 2.
- Using a negative number of digits in SQLite to round to hundreds: SQLite treats it as 0 (see the matrix).
