TRUNC()
Truncates a number toward zero, removing digits past a given precision.
Description
TRUNC cuts off digits beyond a specified number of decimal places, moving
toward zero (unlike ROUND, it never rounds). TRUNC(3.987, 1) is 3.9, and
TRUNC(-3.987, 1) is -3.9. It's ideal when you want to drop precision without
rounding up or down.
Syntax
TRUNC(expression)
TRUNC(expression, n)Parameters
| Name | Description | Optional |
|---|---|---|
| expression | A numeric column or expression. | No |
| n | Decimal places to keep (default 0). | Yes |
Return Type
Returns the same numeric type as the input.
Examples
Store (Customers/Orders/Products)
Loading database engine...
Store (Customers/Orders/Products)
Loading database engine...
TRUNC vs ROUND
TRUNC just chops digits; ROUND adjusts the last kept digit. Use TRUNC
when you must not round.
Common Mistakes
- Expecting rounding.
TRUNCnever rounds —TRUNC(3.9)is3, not4. - Confusing with FLOOR.
TRUNCmoves toward zero;FLOORmoves down.TRUNC(-3.9)is-3,FLOOR(-3.9)is-4. - Wrong precision sign. A negative
ntruncates to the left of the decimal.
Related Functions
See also: ROUND, FLOOR, CEIL.