Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Numeric value to words

Posted on 2004-09-04
14
Medium Priority
?
364 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
New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

 
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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

661 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