0

How can I convert words to numbers in JavaScript?

As an example is there a javascript/jQuery library/plugin that will take a string "one hundred and two" and return the int 102.

var myInt = stringToInt("one hundred and two");
console.log(myInt);
=> 102

I specifically require a string-to-number conversion and not number-to-string conversion. Suggested solutions have come up short:

jsfiddle.net/joepegler/g0vwy44n 
Joe Austin
  • 557
  • 7
  • 24

1 Answers1

2

While it should not be very difficult to do it yourself as an exercise, here's a script that does that

http://javascript.about.com/library/bltoword.htm

EDIT : I misread your question, you wanted the opposite. Well, check this answer instead then https://stackoverflow.com/a/12014376/4651083

Community
  • 1
  • 1
Dimitris Karagiannis
  • 8,942
  • 8
  • 38
  • 63