Documentation / @ripl/utilities / roundTo
Function: roundTo()
roundTo(
value,precision?):number
Defined in: packages/utilities/src/number.ts:87
Rounds a number to at most precision decimal places, stripping any trailing zeros.
Unlike Number.prototype.toFixed (which returns a fixed-width string), this returns a number so integers stay integers (roundTo(5, 2) === 5) and fractional values are capped (roundTo(1.005, 2) === 1.01, roundTo(3.14159, 2) === 3.14). Non-finite values pass through unchanged. Used as the default precision cap for chart labels, axes, and tooltips.
Parameters
| Parameter | Type | Default value |
|---|---|---|
value | number | undefined |
precision | number | 2 |
Returns
number