PostgreSQL TRUNC Function

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

PostgreSQL TRUNC() function

TRUNC() function

The PostgreSQL trunc() function is used to truncate a number to a particular decimal places. If no decimal places are provided it truncate toward zero(0).

Syntax :

trunc()

PostgreSQL Version : 9.3

Pictorial presentation of PostgreSQL TRUNC() function

 

Example 1: PostgreSQL TRUNC() function

SELECT TRUNC(67.456) AS "Truncate";

Output :

 Truncate
----------
       67
(1 row)

Example 2: PostgreSQL TRUNC() function

SELECT TRUNC(67.456,1) AS "Truncate upto 1 decimal";

Output :

 Truncate upto 1 decimal
-------------------------
                    67.4
(1 row)

Example 3: PostgreSQL TRUNC() function

SELECT TRUNC(67.456,2) AS "Truncate upto 2 decimal";

Output :

 Truncate upto 2 decimal
-------------------------
                   67.45
(1 row)