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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

trunc(x)  |  trunc(x numeric, places)

Parameters

ParameterDescription
x A number (integer, numeric or double precision).
places optional Decimal places to keep. Default: 0

Return value

A number.

Examples

Toward zero
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.

trunc() vs floor()
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

Was this page helpful?