TRUNCATE
functionsupportedCore SQL functionsRounds the input expression down to the nearest (or equal) value closer to zero. Depending on the value you specify as the scale parameter, the transformation can remove: - All the digits after the decimal point, producing an integer value. This is the default and most common use of TRUNC for numbers. - Some of the significant digits after the decimal point, producing a less precise value. - All the significant digits after the decimal point and some significant digits to the left of the decimal point, producing a value that is a multiple of 10, 100, or other power of 10. The TRUNCATE and TRUNC functions are synonymous. Note TRUNC is overloaded. It can also be used with date/time values to truncate dates, times, and timestamps to a specified part. The numeric TRUNC has one required and one optional parameter. The date/time TRUNC has two required parameters.
Syntax
supportedpartialnot supportednot scored
TRUNCATE( <input_expr> [ , <scale_expr> ] )
TRUNC( <input_expr> [ , <scale_expr> ] )
Parameters
| Name | Required | Description |
|---|---|---|
input_expr | required | The value or expression to operate on. The data type must be one of the numeric data types, such as DECFLOAT, FLOAT, or NUMBER. |
scale_expr | required | The number of digits to include after the decimal point. The default scale_expr is zero, meaning that the function removes all digits after the decimal point. For information about negative scales, see the Usage notes below. |
Returns
- If the input is a NUMBER value, the data type of the returned value is NUMBER(precision, scale). If the input scale was greater than or equal to zero, then the output scale generally matches the input scale. If the input scale was negative, then the output scale is 0. For example: The data type returned by TRUNCATE(3.14, 1) is NUMBER(4, 1). - The data type returned by TRUNCATE(3.14, 0) is NUMBER(4, 0). - The data type returned by TRUNCATE(33.33, -1) is NUMBER(5, 0). If the scale is zero, then the value is effectively an integer. - If the input is a FLOAT value, the data type of the returned value is FLOAT. - If the input is a DECFLOAT value, the data type of the returned value is DECFLOAT.
Usage notes
- If scale_expr is negative, then it specifies the number of places before the decimal point to which to adjust the number. For example, if the scale is -2, then the result is a multiple of 100.
- If scale_expr is larger than the input expression scale, the function does not have any effect.
- If either the input_expr or the scale_expr is NULL, then the result is NULL.
- Truncation is performed towards 0, not towards the smaller number. For example, TRUNCATE(-9.6) results in -9, not -10.