Function toNumber

  • Converts a given string formatted value into a number.

    Parameters

    • str: string

      The string value to be converted into a number.

    • returnStrings: boolean = false

      A flag indicating whether to return the input string if it is not a valid number. Default value is false.

    Returns string | number

    • The number value if the input string is a valid number. If the input string is not a valid number and returnStrings is true, the function returns the input string. If the input string is not a valid number and returnStrings is false, the function logs a warning message and returns ``.

    Example

    console.log(toNumber("-23.32")); // Output: -23.32
    console.log(toNumber("abc")); // Output: "abc NaN"

Generated using TypeDoc