Try it yourself:


trunc(): remove a fractional part

trunc(x) rounds toward zero. trunc(3.8) is 3 and trunc(-3.8) is −3.

Compare rounding rules

Truncation differs from floor(), which sends −3.8 to −4, and ceil(), which sends it to −3. Use round() for nearest-integer behavior.

Useful checks

Use isInteger() to see whether truncation changes a value, abs() for magnitude, and sign() for direction.

Caveat

Truncation discards information. Do not use it to validate counts unless rounding toward zero is the intended rule.

All functions