roundNumber()function

roundNumber(num: number, precision = 0): number
ParamType
numnumber
The number to round. required
precisionunknown
Maximum number of digits shown after the decimal point (defaults to 10). Defaults to 0
Return
number
The number rounded to the specified precision.

Round a number to a specified set of decimal places.

  • Better than Math.round() because it allows a precision argument.
  • Better than num.toFixed() because it trims excess 0 zeroes.

Examples

roundNumber(1.2345, 2) // 1.23