Skip to content

round

Rounds a number to a specified precision.

199 bytes

Usage

The _.round function rounds a given number to a specified precision.

import * as _ from 'radashi'
_.round(123.456) // => 123
_.round(1234.56, -2) // => 1200

Precision

The precision argument is limited to be within the range of -323 to +292. Without this limit, precision values outside this range can result in NaN.

Rounding Method

You may provide a custom rounding method. The default is Math.round.

_.round(4.001, 2, Math.ceil) // => 4.01
_.round(4.089, 2, Math.floor) // => 4.08