13 Replies Latest reply on Jul 13, 2017 4:59 AM by Test Screen Name

    How do you convert numeric values into english words?

    jpayne1975

      I am interested in creating a field in adobe acrobat that references a total dollar amount field. I want the java script to convert the numeric number into a written word, such as $59.59 as Fifty Nine and 59/100. I have no experience writing java script code and would really like some help on how this can get done. Its also important to embed in the programming that if their is no numeric value to reference, then nothing get referenced. This means an empty text box. Thanks for any help.

        • 1. Re: How do you convert numeric values into english words?
          gkaiseril MVP & Adobe Community Professional

          With the full distribution CD/DVD of Acrobat, Adobe included sample forms. One of them is a check and if you enter a numeric amount into the Amount field then the written amount field fills in with the words.

           

          The document level script:

           

          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;
                    else
                       cWords = ConvertToHundreds(nLeft) + " " + cWords;
                 }
                 nLeft = Math.floor(nLeft / 1000);
             }
             num = Math.round(num * 100) % 100;
             if (num > 0)
                cWords += ConvertToHundreds(num) + " Cents";
             else
                cWords += "Zero Cents";

             return cWords;
          }

           

           

          You can use the following script for the custom calculation for the words field when the number field is named "Number":

           

          event.value = "";

          var f = this.getField("Number");

          if(f.valueAsString != "") {

          event.value = ConvertToWords(f.value);

          }

           

          See Entering Document Scripts by Thom Parker to see how to enter a document level script into a PDF form or file.

          • 2. Re: How do you convert numeric values into english words?
            Percy_H13

            Hi Gkaiseril,

             

            I am having a similar issue with Acrobat X.

             

            My problem is that I want to be able to change the words to numbers.  The field "Number" is the field that contains a numerical value (for example $13,300) and I want the  field "Convert to words" to show an amount of Thirteen Thousand Three Hundred Dollars.

             

            I have attempted to use Javascript without any success.

             

            Are you able to shed any light on this for me?

             

            Thanks for your assistance in advance!

             

            Chris

            • 3. Re: How do you convert numeric values into english words?
              Test Screen Name Most Valuable Participant

              What is the JavaScript you are using to do the conversion, in full?

              • 4. Re: How do you convert numeric values into english words?
                Percy_H13 Level 1

                Im using the below script...... I'm a complete novice at this and helping a friend out with it.

                 

                Any info is appreciated.

                 

                 

                 

                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;
                          else
                             cWords = ConvertToHundreds(nLeft) + " " + cWords;
                       }
                       nLeft = Math.floor(nLeft / 1000);
                   }
                   num = Math.round(num * 100) % 100;
                   if (num > 0)
                      cWords += ConvertToHundreds(num) + " Cents";
                   else
                      cWords += "Zero Cents";

                   return cWords;
                }

                 

                 

                You can use the following script for the custom calculation for the words field when the number field is named "Number":

                 

                event.value = "";

                var f = this.getField("Number");

                if(f.valueAsString != "") {

                event.value = ConvertToWords(f.value);

                }

                • 5. Re: How do you convert numeric values into english words?
                  gkaiseril MVP & Adobe Community Professional

                  That script should be placed as a document level script. And then in the filed where the text will appear one uses the following custom JavaScript calculation:

                   

                  event.value = ConvertToWords(this.getField("Name of number field to convert").value);

                   

                  You will have the change 'Name of number field to convert' to the name of the field whose value you want converted.

                   

                  With the full distribution disk of Acrobat there is a sample check form that this script comes from.

                  • 6. Re: How do you convert numeric values into english words?
                    DGail

                    Thank you all for the scripts here... I was able to make my own check template using this thread!

                     

                    If anybody knows how to autofill the remaining portion of the written amount field with asterisks, that would make my template perfect.

                    (i.e. I want to input "$1,200"

                    and have the next field auto-populate with:

                    "One thousand two hundred and 00/100***********************").

                     

                    Anyone know how to tweak the script so that this would be accomplished?

                    • 7. Re: How do you convert numeric values into english words?
                      gkaiseril MVP & Adobe Community Professional

                      You have to know the length of the field you want to fill. You can then call the function and append the "*" at the end of the returned value and trim the result using the substr method..

                       

                      event.value = "******************************************"; // value for no value

                      var f = this.getField("Number");

                      if(f.valueAsString != "") {

                      // convert to words and concatenate the "*" and make final string 45 characters long

                      event.value = (ConvertToWords(f.value) + event.value).substr(0, 45);

                      }

                      • 8. Re: How do you convert numeric values into english words?
                        DGail Level 1

                        That worked perfectly... thank you so much!

                        • 9. Re: How do you convert numeric values into english words?
                          sowmya D

                          Hi ,

                          1. Using Form Calc , there's default function called

                          WordNum(Cell5, 2)

                          here Cell5 is your numerical field and this code is mentioned in text field were english words should be displayed.

                          for example :

                          data.#subform[0].Table1.Row9.Cell6::calculate - (FormCalc, client)

                          WordNum(Cell5, 2)

                          If Dollar format is not required then following script is used .

                          Replace(Replace(Replace(Replace(WordNum(Cell5,2

                          ), "Dollars ",""), "Dollar ",""), "Cents", ""), "Cent", "")

                           

                          Very simple .Hope this will help you to resolve the requirement .

                          • 10. Re: How do you convert numeric values into english words?
                            Bernd Alheit Adobe Community Professional & MVP

                            Info: This will not work in a Acrobat form, only in a XFA form.

                            • 11. Re: How do you convert numeric values into english words?
                              sowmya D Level 1

                              Above mentioned function is working fine in adobe form PDF (i.e in Adobe Live Cycle designer server ).

                              • 12. Re: How do you convert numeric values into english words?
                                Bernd Alheit Adobe Community Professional & MVP

                                LiveCycle Designer creates XFA forms, not Acrobat forms.

                                • 13. Re: How do you convert numeric values into english words?
                                  Test Screen Name Most Valuable Participant

                                  You may not be aware but most people don't make XFA forms. This forum is used to discuss Acroforms.