TRUNCATE

functionsupportedCore SQL functions

docs.snowflake.com ↗

Numeric functionsDate & time functions

Rounds 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

NameRequiredDescription
input_exprrequiredThe value or expression to operate on. The data type must be one of the numeric data types, such as DECFLOAT, FLOAT, or NUMBER.
scale_exprrequiredThe 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

See also