convnum
    Preparing search index...

    Function convertFrom

    • Generalized function to convert a string to a number based on the specified type. Supports all number formats including decimal, binary, octal, hexadecimal, Roman numerals, English/French words, Chinese characters, letters, and more. Case and format properties in TypeInfo are ignored during parsing (they're used for output formatting). For Chinese types, Traditional Chinese input is automatically converted to Simplified before processing, as the internal conversion functions work with Simplified Chinese.

      Parameters

      • str: string

        The input string to convert (e.g., 'IV', 'twenty-one', '一百二十三', '萬億')

      • typeInfo: NumType | TypeInfo

        The type information object specifying how to interpret the string, or the type name as a string

      Returns number

      The converted number

      Error if the type is not supported or conversion fails

      convertFrom('123', { type: 'decimal' }) // returns 123
      convertFrom('IV', { type: 'roman' }) // returns 4
      convertFrom('twenty-one', { type: 'english_words' }) // returns 21
      convertFrom('A', { type: 'latin_letter' }) // returns 1
      convertFrom('FF', { type: 'hexadecimal' }) // returns 255
      convertFrom('January', { type: 'month_name' }) // returns 1
      convertFrom('一百二十三', { type: 'chinese_words' }) // returns 123
      convertFrom('萬億', { type: 'chinese_words' }) // returns 10000000000000 (Traditional converted to Simplified first)
      convertFrom('Aries', { type: 'astrological_sign' }) // returns 1