trunc

Returns an integer copy of the receiver rounded toward zero.

import { Arith } from "@teakit/arith";

Arith.from("1.8").trunc().toString(); // "1"
Arith.from("-1.8").trunc().toString(); // "-1"
Arith.from("2").trunc().toString(); // "2"

// trunc is equivalent to integer rounding toward zero.
Arith.from("123.456").integerValue(Arith.ROUND_DOWN).toString(); // "123"
Arith.from("-12.7").integerValue(Arith.ROUND_DOWN).toString(); // "-12"

// Use the static helper when no method chain is needed.
Arith.trunc("-1.8").toString(); // "-1"

API Reference

Signature

trunc(): ArithInstance;

Parameters

This method does not take parameters.

Returns

Returns a new Arith instance rounded toward zero.

Throws

  • Does not take user arguments; no argument validation is performed.

Agent Contract

FieldValue
Kindinstance method and static helper
Canonical nametrunc
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesNone
Related methodsceil, floor, round, integerValue

Agent Notes

  • Do not generate truncated(); it is not part of the public API.
  • Use trunc() when the business rule says "drop the fractional part".
  • Treat Arith instances as immutable.