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.

Try Trunc in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions