The English2Number Javascript Library

What it does

Converts English words to numbers.

The following inputs will return this number: 123,456,789,001

"one hundred and twenty-three billion, four hundred and fifty-six million, seven hundred and eighty-nine thousand and one" (cardinal)

"a hundred and twenty-three billion, four hundred and fifty-six million, seven hundred and eighty-nine thousand and one" (cardinal)

"one hundred twenty-three billion, four hundred fifty-six million, seven hundred eighty-nine thousand, one" (cardinal)

"one hundred twenty-three billion four hundred fifty-six million seven hundred eighty-nine thousand one" (cardinal)

"a hundred twenty-three billion, four hundred fifty-six million, seven hundred eighty-nine thousand, and one" (cardinal)

"a hundred and twenty-three billion, four hundred and fifty-six million, seven hundred and eighty-nine thousand and first" (ordinal)

"one hundred twenty-three billion, four hundred fifty-six million, seven hundred eighty-nine thousand, first" (ordinal)

And in fact really any reasonable combination of cardinal and ordinal English speech patterns for describing numbers.

What's the limit?

It doesn't parse anything bigger than decillion, which is 33 zeros after the 1, or 1000000000000000000000000000000000.

If you think it should, it would be trivial to add larger number support, but Javascript can't realistically represent that precision anyway. Perhaps a BigNumber version of this library would be in order.

Installation

npm install --save english2number

Example Usage

As a module:

var toNumber = require ( " english2number " ) ; toNumber ( " one hundred and twenty-three billion, four hundred and fifty-six million, seven hundred and eighty-nine thousand and one " )

numeral.js is an amazing library for dealing with numerals, but it lacks support for English parsing.

Contributing

Pull requests are welcome, please file any bugs on https://github.com/tsavo/english2number-js