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): numberParameters
word(string): The English word representation of a number to convert (cardinal or ordinal).
Return Value
number: The numeric value of the input, orNaNif 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:
convertWordsToNumberwordToNumberconvertWordToNumber
See Also
- numberToWords - For cardinal word representation of numbers.
- numberToWordsOrdinal - For ordinal word representation of numbers.
Last updated: Mon, Jun 15, 2026 11:04:47AM (UTC)
