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

Number to Text

Lady Di
Registered: Feb 18 2009
Posts: 86
Answered

Is there a way to convert a number string to a text string? I am working on a form where the salesperson has to enter a numerical dollar amount and a written dollar amount. There have been several instances where the written amount does not match the numerical amount. I would like to set the form up so that when the salesperson enters the numerical amount, the written amount automatically populates. In other words, if the salesperson enters $10 in one field, I would like the next field to automatically show "ten dollars". Is this possible?

My Product Information:
Acrobat Pro 8.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Adobe has provided this as a document function in a sample form called "check.pdf".

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

George Kaiser

Lady Di
Registered: Feb 18 2009
Posts: 86
I placed the code you provided in my form as a document level JavaScript. What do I need to do next? How do I get it to populate the written amount field? I apologize for my ignorance, but I am new to writing JavaScript.
Lady Di
Registered: Feb 18 2009
Posts: 86
I cannot find the check.pdf file on my computer. Where should this file be located?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The sample form was part of the Acrobat CD-Rom distribution disk and does not get installed.

You need to call the function 'ConvertToWords(num)' with the word 'num' replaced by the value you want converted to words and it will return the character string for the number.

In a text field, you can enter the following code in the 'Custom calculation script' field:
var nValue = this.getField("NumberFieldName").value;event.value = ConvertToWords(nValue);

George Kaiser

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
As noted you need to place a special script as a document level script, [url=http://www.acrobatusers.com/tutorials/2007/07/js_document_scripts]Entering Document Scripts[/url] by Thom Parker. Then you need to know your field names. Assuming you have a numeric field with a field name of "Number" that you want converted to words and a text field names 'Words', you need to add the following script to the custom calculation script for the 'Words' field:
var nValue = this.getField("Number").value;event.value = ConvertToWords(nValue);

You should look over the tutorials and eSeminars on demand to learn the basics of creating and using fields.

George Kaiser

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Are you creating your forms in LiveCycle Designer?

Has the form had security restrictions applied to it?

George Kaiser

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
If you are using LiveCycle Designer, then look at the 'WordNum' function within LiveCycle Designer.

George Kaiser

thibosshere
Registered: Jul 12 2010
Posts: 7
Sir,
I am try to do this but not working number to words conversion in Adobe LiveCycle Designer.i am placing two text box in my Adobe LiveCycle Designer layout then coping above code in Java Script Exit event then execute my form not working and i am checking Documnent properties - - >Security Tab - -> it shows this pdf form has restrict some operation. What should i do ?
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Did you add a password or extend form rights to this PDF?

George Kaiser

thibosshere
Registered: Jul 12 2010
Posts: 7
No password or extend form rights to this PDF. I only place the two textbox only.