In this PostgreSQL post explains how to use the PostgreSQL round function with syntax and examples.
The PostgreSQL round function returns a number rounded to a certain number of decimal places.
The syntax for the round function in PostgreSQL is:
round( number, [ decimal_places ] )
The number to round.
The number of decimal places rounded to. This value must be a positive or negative integer. If this parameter is omitted, the round function will round the number to 0 decimal places.
The round function can be used in the following versions of PostgreSQL:
Let's look at some PostgreSQL round function examples and explore how to use the round function in PostgreSQL.
For example:
postgres=# SELECT round(125.315);
round
-------
125
(1 row)
postgres=# SELECT round(125.315, 0);
round
-------
125
(1 row)
postgres=# SELECT round(125.315, 1);
round
-------
125.3
(1 row)
postgres=# SELECT round(125.315, 2);
round
--------
125.32
(1 row)
postgres=# SELECT round(125.315, -1);
round
-------
130
(1 row)
postgres=# SELECT round(125.315, -2);
round
-------
100
(1 row)
postgres=# SELECT round(-125.315);
round
-------
-125
(1 row)