Skip to content

Number Helpers

Utility functions for working with number operations.

FunctionDescription
ceil / floornative JS Math.ceil() / Math.floor() (ES1)
clampClamps a number between min and max values
correctFloatCorrects floating-point arithmetic errors by rounding to a given number of significant digits.
extractNumberExtracts the first number embedded anywhere in a string, or passes through a number.
formatCompactFormats a number using compact notation (e.g.
formatSizeFormat a byte count into a human-readable string with the appropriate unit.
inRangeChecks whether a number falls within [min, max] (both inclusive by default).
isEvenChecks if a value is an even integer.
isNegativeChecks if a value is a number less than 0.
isOddChecks if a value is an odd integer.
isPositiveChecks if a value is a number greater than 0.
lerpLinearly interpolates between start and end by the factor t.
meanCalculates the arithmetic mean (average) of an array of numbers.
min / maxnative JS Math.min(...arr) / Math.max(...arr) (ES1)
randomBetweenGenerates a random number between min and max (inclusive)
randomIntBetweenGenerates a random integer between min and max (inclusive)
roundToRounds a number to specified decimal places
sumCalculates the sum of an array of numbers.
toInt / toFloatnative JS parseInt(str, 10) / parseFloat(str) (ES1)