I am trying to write a program that can do math with English words.
For example, I want to be able to do something like
"four thousand and three" + "seven thousand and twenty nine"
and get output like
"eleven thousand and thirty two"
Is it possible to do this in jQuery?
Yes, I have written a jQuery plug-in called Word Math that was made for this exact purpose.
For the example in your question, you can just copy and paste this code
and voila! You’ve performed some word math.
Word Math can also do conversion from Javascript numbers to words and vice versa:
You can read more about how to use the Word Math plugin on its readme page
EDIT: There is now a version of Word Math that does not depend on jQuery. To use it, you should download the
wordMath.vanilla.min.jsfile on the gitHub repository instead of thewordMath.jquery.jsfile.The usage of the jQuery-less version is exactly the same as the jQuery version, except that you do not need the
$.prefix in the calls. In other words, instead of doingyou would instead write