Toolbox-XToolbox-X

Convert Words to Number

Converts an English cardinal or ordinal word string into its numeric value.

wordsToNumber

The wordsToNumber function converts an English cardinal or ordinal word string into its numeric value.

Warning

  • For very large numbers (quintillion and beyond), results may not always be correct due to numeric precision limits.
  • Mixed words with non-numeric tokens (e.g., "seventy-seven cats") will return NaN.

Function Signature

function wordsToNumber(word: string): number

Parameters

  • word (string): The English word representation of a number to convert (cardinal or ordinal).

Return Value

  • number: The numeric value of the input, or NaN if the input cannot be parsed.

Example Usage

playground.ts

Supported Features

  • Cardinal numbers: "one", "two", ..., "one hundred", etc.
  • Ordinal numbers: "first", "second", ..., "twenty-first", etc.
  • Large scales: "thousand", "million", ..., "quintillion" (up to $10^20$).
  • Negative numbers: prefixed with "minus" or "negative".
  • Hyphenated or spaced numbers: "forty-two" or "forty two".
  • "And" in numbers: "one hundred and one".
  • Numeric strings: "1,234", "042", "3.14".

Aliases

The following aliases can be used for the wordsToNumber function:

  • convertWordsToNumber
  • wordToNumber
  • convertWordToNumber

See Also

Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)

On this page