convnum
    Preparing search index...

    Function convertTo

    • Generalized function to convert a number to a string based on the specified type. Supports precise control over output formatting through case and format properties. Case options: 'lower', 'upper', 'sentence' (first letter capitalized), 'title' (each word capitalized). Format options: 'short' or 'long' for dates/months. For Chinese types, supports Traditional/Simplified script conversion via zhst property:

      • zhst: 0 = output Simplified Chinese (default)
      • zhst: 1 = output Traditional Chinese (converted from Simplified)
      • zhst: 2 = output Simplified Chinese (ambiguous, defaults to Simplified)

      Parameters

      • num: number

        The input number to convert (e.g., 4, 21, 123)

      • typeInfo: NumType | TypeInfo

        The target type information object including type, case, format, and zhst specifications, or the type name as a string

      Returns string

      The converted string formatted according to the specified case, format, and Chinese script

      Error if the type is not supported or conversion fails

      For circular numeral types (all types present in numeralLength: latin_letter, greek_letter, month_name, astrological_sign, etc.), automatically handles out-of-range numbers by wrapping them using circular arithmetic. The circular handling is included in convertTo(), some specific toAbc() functions include it too but many don't

      convertTo(4, { type: 'roman', case: 'upper' }) // returns 'IV'
      convertTo(4, { type: 'roman', case: 'lower' }) // returns 'iv'
      convertTo(21, { type: 'english_words', case: 'title' }) // returns 'Twenty-One'
      convertTo(21, { type: 'english_words', case: 'upper' }) // returns 'TWENTY-ONE'
      convertTo(1, { type: 'latin_letter', case: 'lower' }) // returns 'a'
      convertTo(27, { type: 'latin_letter', case: 'lower' }) // returns 'a' (wraps around)
      convertTo(255, { type: 'hexadecimal', case: 'upper' }) // returns 'FF'
      convertTo(1, { type: 'month_name', case: 'sentence', format: 'long' }) // returns 'January'
      convertTo(1, { type: 'month_name', case: 'upper', format: 'short' }) // returns 'JAN'
      convertTo(13, { type: 'month_name', case: 'upper', format: 'short' }) // returns 'JAN' (wraps to January)
      convertTo(123, { type: 'chinese_words' }) // returns '一百二十三' (Simplified)
      convertTo(123, { type: 'chinese_words', zhst: 1 }) // returns '一百二十三' (Traditional, same in this case)
      convertTo(10000000000000, { type: 'chinese_words', zhst: 1 }) // returns '萬億' (Traditional)
      convertTo(1, { type: 'astrological_sign', case: 'lower' }) // returns 'aries'
      convertTo(13, { type: 'astrological_sign', case: 'lower' }) // returns 'aries' (wraps around)
      convertTo(7, { type: 'day_of_week', case: 'lower' }) // returns 'sunday' (wraps around)