Function roundWith

  • Round a given number with a given precision and rounding function. Shifts with exponential notation to avoid floating-point issues.

    Parameters

    • number: number

      the number to round.

    • precision: number

      the number of decimal points.

    • round: ((n) => number) = Math.round

      the rounding function to use.

        • (n): number
        • Parameters

          • n: number

          Returns number

    Returns number

    The rounded number.

    Throws

    if the given number is not finite or NaN.

    Example

    roundWith(1.2345, 2);;
    //=> 1.23
    roundWith(1.2345, 2, Math.ceil);;
    //=> 1.24

Generated using TypeDoc