Number Utilities
Mathematical helpers, number formatting, clamping, rounding, and percentage utilities in sc-fns/number.
The sc-fns/number module provides precision math and formatting utilities.
ts
clamp
Restricts a numeric value to lie within an inclusive [min, max] interval.
Signature
ts
Examples
ts
formatNumber
Formats numbers with locale-aware thousands separators, precision, compact notations (e.g. 1.5M), or currency units using Intl.NumberFormat.
Signature
ts
Examples
ts
roundTo
Accurately rounds a floating-point number to a specified number of decimal places, avoiding common JavaScript floating-point errors.
Signature
ts
Examples
ts
percentage
Calculates what percentage partial is of total. Handles zero denominators safely without throwing NaN or Infinity.
Signature
ts
Examples
ts
isEven & isOdd
Parity checking guards for integers.
Examples
ts
How is this guide?
Last updated on October 25, 2026