1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

Numbers to Words

Join the Discussion

Questions? Comments?

Lots of programming involves calculations with numbers. The problem comes when you want to display the result of your calculations and just printing the plain number isn't going to be good enough for what you want. You can of course format the number by adding commas and so forth but sometimes a number as a number isn't appropriate and you need the equivalent of the number in words. Converting a number into words isn't exactly the most straightforward of tasks but it can be done using javascript as the following number to word conversion form demonstrates.

If you want to be able to do these conversions on your site then the you will need a Javascript that can do the conversion for you. The simplest way to get one is to take a copy of mine. The first step to obtain it is to select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called toword.js.

Next you link the script into the head of your page using the following code:

<script type="text/javascript" src="toword.js">

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);

Note that this function can convert numbers as big as 999,999,999,999,999 with as many decimal places as you like into words. 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 all acceptable content for the number but it will return "not a number" if it contains anything else. If you want to convert negativ numbers of currency values to words you should remove those symbols from the number first and convert those to words separately.

©2016 About.com. All rights reserved.