Solved

Numeric value to words

Posted on 2004-09-04
14
356 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PDF - Populate hidden filed from drop down list 5 68
Barcode detail gets lost in PDF 3 86
PDF links 3 46
3d PDF Reader 5 32
Update 21-May-2015: I temporarily removed the source code to make major changes to the program. Regards, Joe INTRODUCTION This article presents a solution to a question (http://www.experts-exchange.com/Programming/Installation/Q_28396542.html)…
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:/…
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now