Skip to content
AgileLogics

Word to Number Converter

Parses English number words (e.g. "one hundred twenty three") into their numeric value.

How it works

Type a number in words (e.g. "one thousand two hundred") and click Convert.

How do you convert number words to digits?

Read the words left to right, building up each group of three digits until you hit a scale word like thousand or million, then multiply that group by the scale and add it to the running total. "Two million three hundred forty thousand five" becomes 2,340,005. This converter does that for English number words, returning plain digits with no separators.

Using the converter

  1. Type or paste the number in words, for example ninety-nine thousand, nine hundred.
  2. Click Convert.
  3. Copy the digits: 99900.

The input is forgiving about formatting. Upper or lower case, hyphens or spaces, commas, and "and" all work:

Input Output
one hundred twenty three 123
One Hundred and Twenty-Three 123
twelve hundred 1200
nineteen hundred eighty-four 1984
seven million and three 7000003
minus forty two -42
negative seven -7
a thousand 1000

How the parser reads a number

The converter reads the words as a sequence of groups, each worth 1 to 999, and each followed by a scale word or by the end of the input. Taking two million three hundred forty thousand five:

  1. "two" is a group of 2, and "million" scales it: 2,000,000.
  2. "three hundred forty" is a group of 340, and "thousand" scales it: 340,000.
  3. "five" is the last group, with no scale: 5.
  4. The total is 2,340,005.

Within a group, a hundreds part (three hundred, optionally followed by "and") comes first, then the tens and units: a tens word can be followed by one unit word (forty two), and a teen word stands on its own. Scale words have to go from largest to smallest, each used once.

There is one informal exception: when the whole number is a single group, the hundreds part may be 10 to 99 hundred, so "twelve hundred" (1200) and "nineteen hundred eighty-four" (1984) work. That form can't be mixed with thousand or bigger.

Vocabulary

Kind Words
Units and teens zero, one, two … nineteen
Tens twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety
Multiplier hundred
Scales thousand, million, billion, trillion
Article (first word only) a, as in a hundred or a thousand
Sign (first word only) negative, minus
Connector and, after hundred or a scale word
Ignored hyphens, commas

Scale words follow the short scale used in modern English, so billion means 10^9.

Words it rejects

Anything outside that vocabulary stops the conversion with "Unrecognized word:" and the offending word, which makes typos easy to find:

Input Error points at
fourty "fourty" (the spelling is forty)
one point five "point" (no decimals)
first, second "first" (no ordinals)
one dozen, half "dozen", "half"
3 thousand "3" (no digits mixed in)
one quadrillion "quadrillion"

Words in the wrong order

Knowing every word isn't enough: the words also have to form a proper number. Sequences that don't are rejected with an error that points at the first word out of place, instead of returning a number you didn't mean:

Input Error
nineteen eighty four "eighty" can't follow "nineteen"; spoken year style isn't a number
one two three "two" can't follow "one"; digits read one by one aren't a number
twenty thirty "thirty" can't follow "twenty"
hundred Put a number before "hundred"
one thousand trillion "trillion" can't come after "thousand"; scales go largest to smallest
negative Add a number after "negative"
one hundred and The number can't end with "and"
one zero "zero" can only be used on its own

If you're converting text that might contain phone numbers, years or digit-by-digit readings, those are exactly the cases that will error, so rewrite them in full (one thousand nine hundred eighty-four). To see the standard wording for a figure, paste the digits into number to words; everything it produces converts back here exactly.

Where this is useful

Typical jobs are pulling amounts out of contracts or cheques that state figures in words, cleaning up transcribed speech, and checking the written-out amount on an invoice against the figure. For spreadsheets and scripts, converting to plain digits first makes the values easy to sort and total, for example with the percentage calculator or the basic calculator.

If you're writing your own parser, the group-and-scale approach above is short enough to implement in a few dozen lines; the JavaScript cheat sheet covers the string methods you'd need for splitting and cleaning the input.

Last updated

Frequently asked questions

What words does the converter understand?
zero to nineteen, the tens from twenty to ninety, hundred, thousand, million, billion and trillion, the word a as the first word (a hundred, a thousand), and negative or minus at the start. Case doesn't matter, hyphens and commas are treated as spaces, and and is allowed after hundred, thousand, million and so on (one hundred and five).
Can it convert decimals like one point five?
No. It works with whole numbers only. A word it doesn't know, such as point, half or dozen, stops the conversion with an error like Unrecognized word: "point".
How do I write years such as nineteen eighty-four?
Use the hundreds form: nineteen hundred eighty-four gives 1984. The spoken year style, nineteen eighty-four, isn't a well-formed number, so the converter shows an error ("eighty" can't follow "nineteen") rather than guessing.
Does it accept 'a hundred' or 'a thousand'?
Yes. a hundred gives 100, a thousand gives 1000 and a hundred thousand gives 100000. The word a is only accepted as the first word of the number.
What's the largest number it can read?
Scale words go up to trillion, so the practical maximum is in the hundreds of trillions, for example nine hundred ninety-nine trillion. Quadrillion and larger scale words aren't recognised.