TRUNC
MySQL equivalent:
Returns a number truncated to the specified number of decimal places without rounding.
PostgreSQL 17.9
TRUNC(num[, decimals])- [ ]optional part
- num
- Number to truncatenumeric | double precision
- decimals
- Decimal places to keep, 0 by default; a negative value zeroes integer digitsintegerOptional
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.9
SELECT TRUNC(27.89);To tenths
PostgreSQL 17.9
SELECT TRUNC(27.89, 1);To tens
PostgreSQL 17.9
SELECT TRUNC(27.89, -1);Details
Extra digits are dropped, also for negative numbers: TRUNC(-1.999, 1) returns -1.9. The decimals argument works only with numeric.