Lots of programming involves calculations with numbers, and you can easily format numbers for display by adding commas, decimals, negative signs and other appropriate characters depending on the kind of number it is.
But you're not always presenting your results as part of a mathematical equation. The Web for the general user is more about words than it is about numbers, so sometimes a number displayed as a number isn't appropriate.
In this case, you need the equivalent of the number in words, not in numerals. This is where you can run into difficulties. How do you convert the numeric results of your calculations when you need the number displayed in words?
Converting a number into words isn't exactly the most straightforward of tasks, but it can be done using JavaScript that isn't too complex.
JavaScript to Convert Numbers into Words
If you want to be able to do these conversions on your site, you will need a JavaScript code that can do the conversion for you. The simplest way to do this is to use the code below; just select the code and copy it into a file called toword.js.

Next, link the script into the head of your page using the following code:
The final step is to call the script to perform the conversion to words for you. To get a number converted to words you just need to call the function passing it the number you want to convert and the corresponding words will be returned.
var words = toWords(num);
Numbers to Words Limitations
Note that this function can convert numbers as big as 999,999,999,999,999 into words and with as many decimal places as you like. If you try to convert a number bigger than that it will return "too big."
Numbers, commas, spaces and a single period for the decimal point are the only acceptable characters that can be used for the number being converted. If it contains anything beyond these characters, it will return "not a number."
Negative Numbers
If you want to convert negative numbers of currency values to words you should remove those symbols from the number first and convert those to words separately.