Solved

Numeric value to words

Posted on 2004-09-04
14
359 Views
Last Modified: 2008-03-10
I have a adobe acrobat (6.0) form with a field that I only takes in currency values (curSalesPrice).  I would like an additional field (curSalesText) to display the numeric value of curSalesPrice in words.  For example, curSalesPrice has $52.00 curSalesText should read Fifty two dollars.

Your help is greatly appreciated.

Thanks!
0
Comment
Question by:chare1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11981669
This is actually not an Acrobat specific problem: You need a JavaScript routine that can convert numbers into English language strings. One example can be found on this page: http://www.merlyn.demon.co.uk/js-maths.htm#Cash
Look at the source (the source for the routine is near the end of the document). All you need to do is port this to Acrobat JavaScript.

I'll give it a try myself.
0
 
LVL 1

Author Comment

by:chare1
ID: 11981692
I tried using NumToString, unfortunately I don't believe this function is available in acrobat.  Also, the script on that page repeatedly mentions tries, in this instance what are they using tries for?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11981799
The "Tries" button is not important for you: It just loops through an array of values that are then copied to the input field (so that you don't have to make up your own test cases).

Here is what you have to do (I don't copy the script here because I don't want to create any copyright problems).

Create a document level JavaScript and name it "convertToEnglish". Add the following code for this function (it takes one parameter):

function convertToEnglish(inp)
{
   return TextCash(inp, 0);
}

Then copy the following items from the JavaScript from the web page I quoted:

Arrays: Affix, Name and Namety
Functions: Small and TextCash

Then, on your form just call convertToEnglish() with the value that you want to convert. E.g. if you have two fields, one with the numeric value, the second one with the string, use something like this:

var f1 = this.getField("Text1");
var f2 = this.getField("Text2");

f2.value = convertToEnglish(f1.value);


0
Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

 
LVL 1

Author Comment

by:chare1
ID: 11981882
So function Setup is not needed even though it contains the "names" of the amounts?  Also, for the document level javascript, I am assuming it is just a file named convertToEnglish.js.  What directory should it be placed in?  The same as that of the form?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11981899
It's not needed, because you copy the array declarations into the global part of your document level script.

A document level script is _NOT_ a file: It's embedded in the PDF document. Go to "Advanced>JavaScript>Document JavaScripts..." and type your new name and click on the "Add" button.
0
 
LVL 1

Author Comment

by:chare1
ID: 11981946
It still did not work.  I placed the script into the document javascripts and the text is still not appearing.  Should I post the exact code ?
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11982146
Do you get any error messages in the JavaScript console/debugger (you can display it with Ctrl-J)?

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11982147
It's up to you if you want to post the code.
0
 
LVL 1

Author Comment

by:chare1
ID: 11982182
I don't get any error message.  Here is what I have under the document javascript:

function convertToEnglish()
{
 return TextCash(inp, 0);
}

Affix = new Array('units',
    'thousand', 'million', 'milliard', 'Tera', 'Peta', 'Exa')
  Name = new Array
    ('zero', 'one', 'two', 'three', 'four', 'five', 'six',
    'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve',
    'thirteen', 'fourteen', 'fifteen',  'sixteen', 'seventeen',
    'eighteen', 'nineteen')
  Namety = new Array('twenty', 'thirty', 'forty',
    'fifty', 'sixty', 'seventy', 'eighty', 'ninety')

function Small(TC, J, K) {
  if (J==0) return TC
  if (J>999) return ' Internal ERROR: J = ' + J + ' (>999)'
  var S = TC
  if (J>99) { S += Name[Math.floor(J/100)] + ' hundred ' ; J %= 100
    if (J>0) S += 'and '
    }
    else if ((S>'') && (J>0) && (K==0)) S += 'AND '
  if (J>19) { S += Namety[Math.floor(J/10)-2] ; J %= 10 ;
    S += ( J>0 ? '-' : ' ') }
  if (J>0) S += Name[J] + ' '
  if (K>0) S += Affix[K] + ' '
  return S }

function TextCash(L, K) {
  if (L==0) return (K>0 ? '' : 'NIL ')
  return Small(TextCash(Math.floor(L/1000), K+1), L%1000, K) }

Here is what I have in the field (under mouse up, run a javascript):

var f1 = this.getField("curBldrDeposit");
var f2 = this.getField("txtPriceWritten");

f2.value = convertToEnglish(f1.value);
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 11982215
This is pretty much what I have (I reformatted the source code a little to make it easier to understand, and I added the ';' after each statement, but it should work as it is).

What type of field is your "mouse up" code associated with? If it's your text field, don't use the "mouse up", but the "on blur" event.

You can find out if your event handler is called at all by adding this to the event handler:

console.println("in mouse-up handler");

Then check the JavaScript console for this message (you can leave the console up while you work with the document).
0
 
LVL 1

Author Comment

by:chare1
ID: 11982230
The error I am receiving is inp is not defined.
0
 
LVL 1

Author Comment

by:chare1
ID: 11982290
I added var inp and now I receive an error stating line 33 has too much recursion.  Here is line 33:

return Small(TextCash(Math.floor(L/1000), K+1), L%1000, K) }
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 125 total points
ID: 11982369
Look at the function definition from my earlier comment:

function convertToEnglish(inp)
{
   return TextCash(inp, 0);
}

The "inp" variable is a function argument.
0
 
LVL 1

Author Comment

by:chare1
ID: 11984525
Thank you for all your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating a Word Form 3 81
merge adobe pdf files 14 125
A PDF to HTML file converter 2 159
How to create a Fillable Form in Adobe Acrobat Pro. 7 26
PaperPort is a popular document imaging/management product from Nuance Communications (http://www.nuance.com/). It is in widespread use by both individuals (http://www.nuance.com/for-individuals/by-product/paperport/index.htm) and businesses (http:/…
Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
In this second video of the Xpdf series, we discuss and demonstrate the PDFimages utility, which, in a single command, is able to extract all the images from a PDF file and save each one in a separate image file (PBM, PPM, or JPG). Download and inst…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question