These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Convert Number To Word

sivakarthick
Registered: Jun 11 2010
Posts: 9
Answered

Hi everyone..!

I am karthick here. I am new to acrobat javascript. Pls any body help me with this....,

There is a text box in my PDF file. When i am typing a number into that text box, that number should change to word and want to diplay it.
For a example:-
i am typing 125.. then i want to display a message like this. 'One hundred twenty five'.

i used one script to display the number what i am typing in the textbox.
var display = this.getField('myValue');
display.value =this.getField('TextField1').value;

Now i dont know how to convert this number to word.

I am kindly request to all of you for help me with this task.

My Product Information:
Acrobat Pro Extended 8.1.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
First , we must know if your are using LiveCycle Designer or Acrobat Forms Tool (Acronyms) to create your form.

LiveCycle Designer has the function "WordNum", see the 'Scripting Reference' under LiveCycle Designer's 'Help' menu bar option, for more information.

For Acrobat forms, Adobe provide an sample check that included an document level JavaScript script with 2 functions to perform this task.
aTens = [ "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];aOnes = [ "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine","Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen","Nineteen" ]; function ConvertToHundreds(num){var cNum, nNum;var cWords = ""; num %= 1000;if (num > 99) {/* Hundreds. */cNum = String(num);nNum = Number(cNum.charAt(0));cWords += aOnes[nNum] + " Hundred";num %= 100;if (num > 0)cWords += " and "} if (num > 19) {/* Tens. */cNum = String(num);nNum = Number(cNum.charAt(0));cWords += aTens[nNum - 2];num %= 10;if (num > 0)cWords += "-";} if (num > 0) {/* Ones and teens. */nNum = Math.floor(num);cWords += aOnes[nNum];} return cWords;} function ConvertToWords(num){var aUnits = [ "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ];var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and ";var nLeft = Math.floor(num);for (var i = 0; nLeft > 0; i++) {if (nLeft % 1000 > 0) {if (i != 0)cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;elsecWords = ConvertToHundreds(nLeft) + " " + cWords;}nLeft = Math.floor(nLeft / 1000);}num = Math.round(num * 100) % 100;if (num > 0)cWords += ConvertToHundreds(num) + " Cents";elsecWords += "Zero Cents"; return cWords;}

So using a text field with no formatting and a number field formatted to 2 decimals called 'Number', you can use the following script in the 'Custom JavaScript calculation' option on the 'Calculate' tab:
var f = this.getField("Number");event.value = ConvertToWords(f.value);

Be sure to properly capitalize and correctly spell the field name.

George Kaiser

sivakarthick
Registered: Jun 11 2010
Posts: 9
Hello sir,
I was searching this for everywhere, but i couldn't find it. thankyou for your help, It's very useful to me. It was worked fine. Thanks a lot again.

Only one more requirement i need.

Can you provide an auto-complete feature in the Adobe form? For example if someone is filling in New York as the city – could it automatically prompt for all cities beginning with N when the user types N?

I am using acrobat form.

Thanks
Merlin
Acrobat 9ExpertTeam
Registered: Mar 1 2006
Posts: 766
Hi,

This article may help you : http://www.devarticles.com/c/a/JavaScript/Suggest-As-You-Type/