Rounds a number to a specified number of decimal places, ensuring precision is maintained.
If no decimal places are provided, the default is 0 (rounds to the nearest integer).
This function uses scientific notation to avoid movable-point precision errors
commonly associated with rounding in JavaScript.
Type declaration
(number:number,decimalPlaces?:number):number
Parameters
number: number
The number to round. If the number is null or not finite (e.g., Infinity), null is returned.
OptionaldecimalPlaces: number
The number of decimal places to round to (default is 0).
Returns number
The rounded number, or null if the input is invalid.
Rounds a number to a specified number of decimal places, ensuring precision is maintained. If no decimal places are provided, the default is 0 (rounds to the nearest integer).
This function uses scientific notation to avoid movable-point precision errors commonly associated with rounding in JavaScript.