Function toNumber

  • Attempts to coerce the specified value to a number. If the value cannot be coerced to a valid number, returns the specified fallback value.

    Parameters

    • value: unknown

      Value to coerce to a number.

    • Optionalfallback: number = 0

      Value to return if the specified value cannot be coerced to a number.

    Returns number

    The specified value as a number if valid, otherwise the specified fallback.