Function Reference

TRUNC

MySQL equivalent:

Returns a number truncated to the specified number of decimal places without rounding.

PostgreSQL 17.5
TRUNC(num[, decimals])

Parameters

numnumeric | double precision
Number to truncate
decimalsintegeroptional
Number of decimal places to keep, 0 by default, can be negative

Return value

A number of the same type as num; for an integer num, double precision without decimals and numeric with decimals

Examples

Without the fractional part

PostgreSQL 17.5
SELECT TRUNC(27.89);
trunc
27

To tenths

PostgreSQL 17.5
SELECT TRUNC(27.89, 1);
trunc
27.8

To tens

PostgreSQL 17.5
SELECT TRUNC(27.89, -1);
trunc
20

Details

Extra digits are dropped, also for negative numbers: TRUNC(-1.999, 1) returns -1.9. The decimals argument works only with numeric.

See also

Where to learn