textConvert
    Preparing search index...

    Function wordsToNumber

    • Parse English number-words back into a number -- the reverse of numbersToWords. Tolerant of case, an optional 'and', and hyphens or spaces between words, even though numbersToWords only ever produces one specific combination of these.

      Parameters

      • text: string

        Number-words to parse, e.g. 'twelve thousand three hundred and forty-five'.

      Returns number

      The parsed number, or NaN for unparseable input -- matching how Number('garbage') signals failure for a numeric return type, since this library's usual string sentinel doesn't fit here.

      wordsToNumber('twenty-three'); // 23
      wordsToNumber('one hundred and five'); // 105
      wordsToNumber('twelve thousand three hundred and forty-five'); // 12345
      wordsToNumber('not a number'); // NaN