@arki/math/rounding

For @arki/[email protected] · source docs/modules/rounding.md

Back to the README.

@arki/math/rounding

One vocabulary everywhere — Decimal, Rational, the float helpers, and formatting all take the same RoundingMode:

ModeMeaning2.5 →−2.5 →
upaway from zero3−3
downtoward zero2−2
ceilingtoward +∞3−2
floortoward −∞2−3
halfUpnearest, ties away from zero (school rounding)3−3
halfDownnearest, ties toward zero2−2
halfEvennearest, ties to even (banker's rounding)2−2
unnecessarythrow RoundingNecessaryError if digits are lost——

Defaults follow intent: display-shaped calls (round, roundTo, Decimal.round, toFixed, formatting) default to halfUp, which is what people expect to see. Precision-shaped calls (dividedBy, toScale, toDecimal) default to unnecessary, so precision is never lost without you asking.

Note that JavaScript's own Math.round(-2.5) is -2 (ties toward +∞) — none of the modes above, and one of the reasons this package exists.

All docs for @arki/[email protected]