Skip to content

TRUNC

Round down a number, either to the next whole number or to a specified decimal precision.

TRUNC(number [, places])

For example:

premdb=# SELECT TRUNC(2.5);
 trunc 
-------
    2
(1 row)
premdb=# SELECT TRUNC(-1.2567);
 trunc 
-------
   -1
(1 row)

The following example truncates the results of an AVG function to three decimal places.

premdb=# SELECT seasonid, AVG(SUBSTR(ftscore,3,1)::INT), 
TRUNC(AVG(SUBSTR(ftscore,3,1)::INT),3) truncgoals FROM match GROUP BY seasonid ORDER BY 2;
 seasonid |            avg            | truncgoals 
----------+---------------------------+------------
      15 | 0.99736842105263157894736 |      0.997
      14 | 1.02368421052631578947368 |      1.024
      13 | 1.06578947368421052631578 |      1.066
       9 | 1.06578947368421052631578 |      1.066
       7 | 1.06842105263157894736842 |      1.068
...

Parent topic:Mathematical Functions