TRUNC (for numbers)
The TRUNC function returns the integer portion of an expression, or, using the optional second argument, returns the expression with a specified number of decimal places. TRUNC does not take the sign of the expression into account; in other words, the decimal portion of both negative and positive expressions trend toward zero.
Syntax
TRUNC (expression, [decimal_places])
Remarks
The input argument expression represents the number to truncate and a NUMERIC or date/time data type as follows:
• If the first argument is a numeric expression (DECIMAL, FLOAT, INTEGER, or STRING), the second argument is the number of decimal places to truncate to.
• If the second argument is greater than the number of decimal places of the first argument, zeros are added to the right of the last significant digit.
• If the second argument is not present, the function returns the integer portion of the expression.
• The output is the same data type as the first input value.
• If either input is NULL, the output is NULL.
Examples
SELECT TRUNC(5.234);
This returns 5.
SELECT TRUNC(5.234, 2);
This returns 5.23.
SELECT TRUNC(5.234, 5);
This returns 5.23400.
TRUNCATE
The TRUNCATE function is the same as TRUNC for date/time and numeric expressions. Refer to
TRUNC (for numbers),
TRUNCATE can also be used in a SQL script to remove (“chop”) a specified number of elements from a VECTOR. Refer to
TRUNCATE, for a description.