Class RoundHelper

Constructors

Properties

PRECISION_ERROR: number = 1e-15

Precision error to check if value is at midpoint.

Methods

  • Checks if a number is at midpoint.

    Parameters

    • x: number

      The number to check.

    Returns boolean

    If the number is at midpoint.

  • Rounds a value using "to even" or "away from zero" algroithm.

    Parameters

    • x: number

      The number to round.

    • mode: number = 1

      Rounding mode. 0 - "away from zero" algorithm. 1 - "to even" algorithm.

    Returns number

    Rounded number using one of two algorithms.

  • Rounds a value to the nearest number. Midpoint values are rounded toward the nearest number that's away from zero.

    Parameters

    • x: number

      The number to round.

    Returns number

    The rounded even number.

  • Rounds a value to the nearest number. Midpoint values are rounded toward the nearest even number.

    Parameters

    • x: number

      The number to round.

    Returns number

    The rounded even number.