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.
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.
npm install --save english2number
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") // 123,456,789,001
Why not numeral.js?
numeral.js is an amazing library for dealing with numerals, but it lacks support for English parsing.
Pull requests are welcome, please file any bugs on https://github.com/tsavo/english2number-js