round

Returns an integer-rounded copy of the receiver as an Arith value.

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

Arith.from("1.5").round().toString(); // "2"
Arith.from("1.5").round(Arith.ROUND_DOWN).toString(); // "1"
Arith.from("-1.5").round(Arith.ROUND_DOWN).toString(); // "-1"

// round is shorthand for integerValue with a rounding mode.
Arith.from("123.456").integerValue(Arith.ROUND_HALF_CEIL).toString(); // "123"

// Use the static helper when no method chain is needed.
Arith.round("1.5", Arith.ROUND_DOWN).toString(); // "1"

API Reference

Signature

round(roundingMode?: ArithRoundingMode): ArithInstance;

Parameters

ParameterTypeRequiredNotes
roundingModeArithRoundingModeNoDefaults to current ROUNDING_MODE.

Returns

Returns a new Arith instance rounded to an integer.

Throws

  • Throws if roundingMode is invalid.

Agent Contract

FieldValue
Kindinstance method and static helper
Canonical nameround
AliasesNone
Mutates receiverNo
ReturnsArithInstance
Accepts (string, base) overloadNo
Configuration dependenciesROUNDING_MODE
Related methodsceil, floor, trunc, integerValue

Agent Notes

  • Prefer round() over integerValue() when integer rounding is the business intent.
  • Use ceil(), floor(), or trunc() for fixed directional rounding.
  • Treat Arith instances as immutable.