Function hexDecValueToNumber

  • Converts a string or number representing a numeric value into a number.

    • If the input is already a number, it is returned as is.
    • If the input is a string starting with #x, it is parsed as a hexadecimal number.
    • Otherwise, the string is parsed using Number(), which supports decimal, hexadecimal (0x), binary (0b), octal (0o), and floating-point literals.

    Returns

    The numeric value parsed from the input. If parsing fails, returns NaN.

    Example

    hexDecValueToNumber(42);           // returns 42
    hexDecValueToNumber("#x2A"); // returns 42 (hexadecimal 2A)
    hexDecValueToNumber("42"); // returns 42 (decimal)
    hexDecValueToNumber("0x2A"); // returns 42 (hexadecimal)
    hexDecValueToNumber("0b101010"); // returns 42 (binary)
    hexDecValueToNumber("0o52"); // returns 42 (octal)

    Parameters

    • value: string | number

      The input value to convert. Can be a number or a string representing a numeric value with optional prefixes.

    Returns number

Generated using TypeDoc