> This page location: Math Functions > ROUND
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL ROUND() Function

The PostgreSQL `ROUND()` function rounds a numeric value to its nearest [integer](../postgresql-tutorial/postgresql-integer) or a number with the number of decimal places.

## Syntax

The following illustrates the syntax of the `ROUND()` function:

```sql
ROUND (source [ , n ] )
```

## Arguments

The `ROUND()` function accepts 2 arguments:

1) source

The `source` argument is a `numeric` or `double precision` value to be rounded.

2) n

The `n` argument is an integer that determines the number of decimal places after rounding.

The `n` argument is optional. If you omit the `n` argument, its default value is 0.

**Note:** When using the `n` argument, the `source` must be of type `numeric`. There is no built-in `round(double precision, integer)` function. To round a `double precision` value to a specific number of decimal places, cast it to `numeric`:

```sql
SELECT ROUND(value::numeric, 2);
```

Alternatively, you can create your own function to handle this automatically:

```sql
CREATE FUNCTION round(double precision, int) RETURNS numeric AS $$
  SELECT round($1::numeric, $2)
$$ LANGUAGE sql;
```

## Return value

The `ROUND()` function returns a result whose type is the same as the input if you omit the second argument.

If you use both arguments, the `ROUND()` function returns a `numeric` value.

## Examples

### 1) Basic ROUND() function example

The following example shows how to round a decimal using the `ROUND()` function:

```sql
SELECT
    ROUND( 10.4 );
```

Because the nearest integer of 10.4 is 10, the function returns 10 as expected:

```
10
```

The following example rounds 10.5:

```sql
SELECT
    ROUND( 10.5 );
```

Output:

```
11
```

### 2) Round to 2 decimal places examples

The following example uses the `ROUND()` function to round a number to the one with 2 decimal places:

```sql
SELECT
    ROUND( 10.812, 2 );
```

Result:

```
10.81
```

And another example of rounding a decimal to 2 decimal places:

```sql
SELECT
    ROUND( 10.817, 2 );
```

Result:

```
10.82
```

You can change the second argument to round a number to specific decimal places.

### 3) Rounding data from table examples

We will use the following `payment` and `customer` tables in the [sample database](../postgresql-getting-started/postgresql-sample-database) for the demonstration.

![customer and payment tables](https://neon.com/postgresqltutorial/customer-and-payment-tables.png)The following statement retrieves the average rental fee that each customer has paid.

```sql
SELECT
    first_name,
    last_name,
    ROUND( AVG( amount ), 2 ) avg_rental
FROM
    payment
INNER JOIN customer
        USING(customer_id)
GROUP BY
    customer_id
ORDER BY
    avg_rental DESC;
```

In this statement, we use the `ROUND()` function to round the average rental fee to 2 decimal places.

Output:

```
first_name  |  last_name   | avg_rental
-------------+--------------+------------
 Brittany    | Riley        |       5.62
 Kevin       | Schuler      |       5.52
 Ruth        | Martinez     |       5.49
 Linda       | Williams     |       5.45
 Paul        | Trout        |       5.39
 Daniel      | Cabral       |       5.30
...
```

The following statement calculates the average number of rentals per customer:

```sql
WITH rental(customer_id,rent) AS
(
    SELECT
        customer_id,
        COUNT( rental_id )
    FROM
        payment
    GROUP BY
        customer_id
)
SELECT
    ROUND(AVG(rent))
FROM
    rental;
```

Output:

```
 round
-------
    24
(1 row)
```

In this example, we used the `ROUND()` function to round the result to an integer.

## Summary

- Use the PostgreSQL `ROUND()` function to round a number to its nearest integer or a number of specified decimal places.
- The single-argument form accepts both `numeric` and `double precision` types.
- The two-argument form (with decimal places) requires the `source` to be `numeric`.

---

## Related docs (Math Functions)

- [ABS](https://neon.com/postgresql/postgresql-math-functions/postgresql-abs)
- [CBRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-cbrt)
- [CEIL](https://neon.com/postgresql/postgresql-math-functions/postgresql-ceil)
- [DEGREES](https://neon.com/postgresql/postgresql-math-functions/postgresql-degrees)
- [DIV](https://neon.com/postgresql/postgresql-math-functions/postgresql-div)
- [EXP](https://neon.com/postgresql/postgresql-math-functions/postgresql-exp)
- [FACTORIAL](https://neon.com/postgresql/postgresql-math-functions/postgresql-factorial)
- [FLOOR](https://neon.com/postgresql/postgresql-math-functions/postgresql-floor)
- [GCD](https://neon.com/postgresql/postgresql-math-functions/postgresql-gcd)
- [LCM](https://neon.com/postgresql/postgresql-math-functions/postgresql-lcm)
- [LN](https://neon.com/postgresql/postgresql-math-functions/postgresql-ln)
- [LOG](https://neon.com/postgresql/postgresql-math-functions/postgresql-log)
- [MOD](https://neon.com/postgresql/postgresql-math-functions/postgresql-mod)
- [MIN_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-min_scale)
- [PI](https://neon.com/postgresql/postgresql-math-functions/postgresql-pi-function)
- [POWER](https://neon.com/postgresql/postgresql-math-functions/postgresql-power)
- [RADIANS](https://neon.com/postgresql/postgresql-math-functions/postgresql-radians)
- [RANDOM](https://neon.com/postgresql/postgresql-math-functions/postgresql-random)
- [SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-scale)
- [SIGN](https://neon.com/postgresql/postgresql-math-functions/postgresql-sign)
- [SQRT](https://neon.com/postgresql/postgresql-math-functions/postgresql-sqrt)
- [TRIM_SCALE](https://neon.com/postgresql/postgresql-math-functions/postgresql-trim_scale)
- [TRUNC](https://neon.com/postgresql/postgresql-math-functions/postgresql-trunc)
- [WIDTH_BUCKET](https://neon.com/postgresql/postgresql-math-functions/postgresql-width_bucket)
