Numeric value to words

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!
LVL 1
chare1Asked:
Who is Participating?
 
Karl Heinz KremerConnect With a Mentor Commented:
Look at the function definition from my earlier comment:

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

The "inp" variable is a function argument.
0
 
Karl Heinz KremerCommented:
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
 
chare1Author Commented:
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
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
Karl Heinz KremerCommented:
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
 
chare1Author Commented:
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
 
Karl Heinz KremerCommented:
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
 
chare1Author Commented:
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
 
Karl Heinz KremerCommented:
Do you get any error messages in the JavaScript console/debugger (you can display it with Ctrl-J)?

0
 
Karl Heinz KremerCommented:
It's up to you if you want to post the code.
0
 
chare1Author Commented:
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
 
Karl Heinz KremerCommented:
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
 
chare1Author Commented:
The error I am receiving is inp is not defined.
0
 
chare1Author Commented:
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
 
chare1Author Commented:
Thank you for all your help!
0
All Courses

From novice to tech pro — start learning today.