TRUNC function

TRUNC removes the decimal values.


SQL> select TRUNC(1.1) from dual;

TRUNC(1.1)
----------
         1

SQL> select TRUNC(1.9) from dual;

TRUNC(1.9)
----------
         1

SQL> select TRUNC(-1.1) from dual;

TRUNC(-1.1)
-----------
         -1

SQL> select TRUNC(-1.9) from dual;

TRUNC(-1.9)
-----------
         -1

SQL> select TRUNC(0) from dual;

  TRUNC(0)
----------
         0

SQL>

TRUNC function may have a second argument to handle precision, which means the distance to the right of the decimal point. The second argument defaults to 0.


SQL> select TRUNC(1.99999) from dual;

TRUNC(1.99999)
--------------
             1

SQL> select TRUNC(1.9,0) from dual;

TRUNC(1.9,0)
------------
           1

SQL> select TRUNC(1.9,1) from dual;

TRUNC(1.9,1)
------------
         1.9

SQL> select TRUNC(1.99,2) from dual;

TRUNC(1.99,2)
-------------
         1.99

SQL> select TRUNC(1.999,3) from dual;

TRUNC(1.999,3)
--------------
         1.999

SQL>

In addition, the second argument, precision, may be negative, which means displacement to the left of the decimal point.


SQL> select TRUNC(19999.99999,0) from dual;

TRUNC(19999.99999,0)
--------------------
               19999

SQL> select TRUNC(19.99999,-1) from dual;

TRUNC(19.99999,-1)
------------------
                10

SQL> select TRUNC(199.99999,-2) from dual;

TRUNC(199.99999,-2)
-------------------
                100

SQL> select TRUNC(1999.99999,-3) from dual;

TRUNC(1999.99999,-3)
--------------------
                1000

SQL>
Home »
Oracle »
Numeric Functions » 

Related: