TRUNCATE or TRUNC

The TRUNCATE function returns expression–1 truncated to some number of places to the right or left of the decimal point.

Read syntax diagramSkip visual syntax diagram
>>-+-TRUNCATE-+--(--expression-1--,--expression-2--)-----------><
   '-TRUNC----'                                        

expression–1
An expression that returns a value of any built-in numeric, character-string, or graphic-string data type. A string argument is converted to double-precision floating point before evaluating the function. For more information about converting strings to double-precision floating point, see DOUBLE_PRECISION or DOUBLE.

If expression-1 is a decimal floating-point data type, the DECFLOAT ROUNDING MODE will not be used. The rounding behavior of TRUNCATE corresponds to a value of ROUND_DOWN. If a different rounding behavior is wanted, use the QUANTIZE function.

expression–2
An expression that returns a value of a built-in small integer, large integer, or big integer data type. The absolute value of integer specifies the number of places to the right of the decimal point for the result if expression–2 is not negative, or to the left of the decimal point if expression–2 is negative.

If expression–2 is not negative, expression–1 is truncated to the expression–2 number of places to the right of the decimal point.

If expression–2 is negative, expression–1 is truncated to the absolute value of (expression–2+1) number of places to the left of the decimal point.

If the absolute value of expression–2 is larger than the number of digits to the left of the decimal point, the result is 0. For example, TRUNCATE(748.58,-4) = 0.

The data type and length attribute of the result are the same as the data type and length attribute of the first argument.

If either argument can be null, the result can be null. If either argument is null, the result is the null value.

Examples