TRUNC

Rounds a number to its integer representation towards 0.

Note

This function is overloaded. The function TRUNC can also modify the precision of DATE and DATETIME values.

See also ROUND.

Syntax

TRUNC( expr )

Arguments

Parameter

Description

expr

Numeric expression

Returns

Returns the same type as the argument supplied.

When using the TRUNC floating point number scalar function, real arguments are automatically cast to double precision.

Notes

  • If the input value is NULL, the result is NULL.

Examples

Rounding to the nearest integer

numbers=> SELECT TRUNC(x) FROM (VALUES (0.0001), (PI()), (-2.718281), (500.1234)) as t(x);
trunc
-----
  0.0
  3.0
 -2.0
500.0

TRUNC vs. ROUND

numbers=> SELECT TRUNC(x), ROUND(x)
.      FROM (VALUES (0.0001), (-0.0001)
.           , (PI()), (-2.718281), (500.1234)) as t(x);
trunc | round
------+------
  0.0 |  -0.0
 -0.0 |  -0.0
  3.0 |   3.0
 -2.0 |  -3.0
500.0 | 500.0