PostgreSQL 18 reference · Math Functions
PostgreSQL TRUNC() Function
Truncate a number toward zero, optionally keeping some decimal places: trunc(2.789, 2) is 2.78.
PostgreSQL 18
Syntax
trunc(x) | trunc(x numeric, places)
Parameters
| Parameter | Description |
|---|---|
x |
A number (integer, numeric or double precision). |
places optional |
Decimal places to keep. Default: 0 |
Return value
A number.
Examples
SELECT trunc(2.7) AS a, trunc(-2.7) AS b, trunc(2.789, 2) AS c;
Output
a | b | c ---+----+------ 2 | -2 | 2.78 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT trunc(-2.7) AS trunc, floor(-2.7) AS floor;
Output
trunc | floor
-------+-------
-2 | -3
(1 row)Run this on your computer — see “Get Started” for setup.
In other languages
TRUNC()· SQLite
Related
ROUND()· Round a number to a given number of decimal places (0 by default). numeric rounds halves away from zero.FLOOR()· Round a number down to the nearest integer: floor(2.9) is 2 and floor(-2.1) is -3.- SQL Aggregate Functions · tutorial