TRUNC

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Truncates a value toward zero, either to an integer or to a specified number of decimal places.

Syntax 

1trunc(<dp_or_numeric>)
2trunc(<v> dp_or_numeric, <s> int)

Arguments 

Required 

  • <dp_or_numeric> / <v>: The double precision or numeric value to truncate.

Optional 

  • <s>: The number of decimal places to truncate to. When omitted, the value is truncated to an integer.

Returns 

Returns the truncated value by using the same data type as the input.

Considerations 

  • trunc truncates toward zero, so it differs from floor for negative values. For example, trunc(-1.9) returns -1, but floor(-1.9) returns -2.
  • A negative value for s truncates to the left of the decimal point.

Examples 

Truncate to an Integer 

Truncate a value toward zero.

1SELECT trunc(2.5) AS result;
2SELECT trunc(-1.9) AS result;

Returns 2 and -1.

Truncate to Decimal Places 

Truncate a value to two decimal places.

1SELECT trunc(42.4382, 2) AS result;

Returns 42.43.

Related Documentation