TRUNC/TRUNCATE Functions

Description

The TRUNC and TRUNCATE function truncates the numbers of the specified argument x to the right of the dec position. If the dec argument is a negative number, it displays 0s to the dec-th position left to the decimal point. Note that the dec argument of the TRUNC function can be omitted, but that of the TRUNCATE function cannot be omitted. If the dec argument is a negative number, it displays 0s to the dec-th position left to the decimal point. The number of digits of the return value to be represented follows the argument x.

Syntax

TRUNC( x[, dec] )

TRUNCATE( x, dec )

Example

--it returns a number truncated to 0 places

SELECT TRUNC(34567.34567), TRUNCATE(34567.34567, 0);

  trunc(34567.34567, 0)   trunc(34567.34567, 0)

============================================

  34567.00000            34567.00000

 

--it returns a number truncated to three decimal places

SELECT TRUNC(34567.34567, 3), TRUNC(-34567.34567, 3);

  trunc(34567.34567, 3)   trunc(-34567.34567, 3)

============================================

  34567.34500           -34567.34500

 

--it returns a number truncated to three digits left of the decimal point

SELECT TRUNC(34567.34567, -3), TRUNC(-34567.34567, -3);

  trunc(34567.34567, -3)   trunc(-34567.34567, -3)

============================================

  34000.00000           -34000.00000