2 Replies Latest reply on Jun 30, 2015 1:49 PM by CCSDVS21

    Format number within event.value script

    CCSDVS21

      I have a script that pulls data from a number field (r18) then adds a space and the text "Annual Vacation Credits".  Right now the result is something like "100000 Annual Vacation Credits".

       

      I'm trying to format the number to include comma's where necessary (ex: 10,000 or 100,000 or 1,000,000 etc).

       

      Here is the current script:

       

      // Get the field values, as strings

       

      var r18 = getField

      ("r18") .valueAsString;

       

      // Combine values

       

      event.value = r18 + " Annual Vacation Credits"

       

      Any help is appreciated

        • 1. Re: Format number within event.value script
          gkaiseril MVP & Adobe Community Professional

          It is possible to format both numbers and dates using the util object in Acrobat JavaScript.

           

          // Get the field value;
          var r18 = getField("r18") .value;
          // format the value and concatenate the text
          event.value = util.printf("%,0 1.2f", r18) + " Annual Vacation Credits";

           

          or

           

          // Get the field value;
          var r18 = getField("r18") .value;
          // format value including text;
          event.value = util.printf("%,0 1.2f Annual Vacation Credits", r18);

          • 2. Re: Format number within event.value script
            CCSDVS21 Level 1

            Works great!  I just tweaked the last line from:

             

            event.value = util.printf("%,0 1.2f", r18) + " Annual Vacation Credits";

             

            to

             

            event.value = util.printf("%,0 1.0f", r18) + " Annual Vacation Credits";

             

            This gives me a result of 5,000 instead of 5,000.00.  Thank you!