PostgreSQL: round Function
This PostgreSQL tutorial explains how to use the PostgreSQL round function with syntax and examples.
Description
The PostgreSQL round function returns a number rounded to a certain number of decimal places.
Syntax
The syntax for the round function in PostgreSQL is:
round( number, [ decimal_places ] )
Parameters or Arguments
- number
- The number to round.
- decimal_places
- 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.
Note
Applies To
The round function can be used in the following versions of PostgreSQL:
- PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4
Example
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)
Advertisements