ctrl + k
On This Page
Functions
Number Utilities
The Number utilities provide functions for manipulating and formatting numbers in JavaScript.
Functions
roundNumber
Rounds a number to a specified number of decimal places.
Precision Handling This function uses a scaling factor to handle floating-point precision issues that can occur with simple
Math.round()
calls.
Parameters
Name | Type | Default | Description |
---|---|---|---|
number | number | The number to round | |
digits | number | 5 | The number of decimal places to round to |
Returns
The rounded number.
Example
This number utility provides a reliable way to round numbers, addressing common floating-point precision issues in JavaScript.