2 Replies Latest reply: Mar 28, 2012 10:45 AM by Gipto RSS

    Numbers to Text

    Gipto

      I'm a acrobat x pro and i need a javascript to convert number to text in a field form,

       

      there's some way to make that?

       

      sorry for my english i know that is bad...

        • 1. Re: Numbers to Text
          GKaiseril CommunityMVP

          When I purchased Acrobat 4 there were samples on the distribution CD and one of them was a check which had an amount field and text field for the number in words. The text field was read only and called the document level function "ConvertToWords" that had an imput parameter of the number and returned the words for the number.

           

          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;
          }

          • 2. Re: Numbers to Text
            Gipto Community Member

            Hey, thanks

            Date: Thu, 15 Mar 2012 21:34:20 -0600

            From: forums@adobe.com

            To: binary_change@hotmail.com

            Subject: Numbers to Text

             

             

             

             

             

             

                  

                       

                       

                       

                Re: Numbers to Text

             

             

                created by GKaiseril in JavaScript - View the full discussion

             

             

             

            When I purchased Acrobat 4 there were samples on the distribution CD and one of them was a check which had an amount field and text field for the number in words. The text field was read only and called the document level function "ConvertToWords" that had an imput parameter of the number and returned the words for the number. 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;

            }

             

             

                 Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4270580#4270580

                 To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4270580#4270580. In the Actions box on the right, click the Stop Email Notifications link.

                  

                 Start a new discussion in JavaScript by email or at Adobe Forums

              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.