Number Helpers
Utility functions for working with number operations.
Functions
Section titled “Functions”| Function | Description |
|---|---|
ceil / floor |
native JS Math.ceil() / Math.floor() (ES1) |
clamp |
Clamps a number between min and max values |
correctFloat |
Corrects floating-point arithmetic errors by rounding to a given number of significant digits. |
extractNumber |
Extracts the first number embedded anywhere in a string, or passes through a `number`. |
formatCompact |
Formats a number using compact notation (e.g. |
formatSize |
Format a byte count into a human-readable string with the appropriate unit. |
inRange |
Checks whether a number falls within `[min, max]` (both inclusive by default). |
isEven |
Checks if a value is an even integer. |
isNegative |
Checks if a value is a number less than 0. |
isOdd |
Checks if a value is an odd integer. |
isPositive |
Checks if a value is a number greater than 0. |
lerp |
Linearly interpolates between `start` and `end` by the factor `t`. |
min / max |
native JS Math.min(...arr) / Math.max(...arr) (ES1) |
randomBetween |
Generates a random number between min and max (inclusive) |
randomIntBetween |
Generates a random integer between min and max (inclusive) |
roundTo |
Rounds a number to specified decimal places |
toInt / toFloat |
native JS parseInt(str, 10) / parseFloat(str) (ES1) |
