Function roundToNearest

  • Round a given number to a given nearest whole number.

    Parameters

    • integer: number

      the number to round.

    • nearest: number = 1

      the nearest whole number to round to.

    Returns number

    The rounded number.

    Throws

    if any of the arguments are either not finite, NaN or not an integer.

    Example

    roundToNearest(111, 1) //=> 111
    roundToNearest(111, 10) //=> 110
    roundToNearest(111, 100) //=> 100
    roundToNearest(111, 1000) //=> 0
    roundToNearest(13, 3) //=> 12

Generated using TypeDoc