1 Reply Latest reply on May 4, 2015 2:42 AM by try67

    Help Fixing Code

    Aman Habib Level 1

      I have been using the adobe code (shown below) for one of my fields in Adobe Acrobat but i need help with the the final result. It's set to have 1 decimal point shown for the final value. I want to update this to have a decimal point on the end of my results but i want it to round up to whole numbers when the event.value is equal to or greater than 100.



           Old code- "74.5" or "156.5"

           New code- "74.5" or "157"



      function Round(Number, DecimalPlaces) {

      return util.printf("%,1 0." + DecimalPlaces + "f", Number);


      var a = this.getField("Text7");

      var b = this.getField("Text5");

      event.value = Round(((a.value - 32)/ (24 / b.value)), 1);




      How do i fix this code up? I am struggling.


      Any help would be greatly appreciated


        • 1. Re: Help Fixing Code
          try67 MVP & Adobe Community Professional

          I've tried to simplify your code and also added a control in case b is empty or zero, which would cause an error in your current code (as division by zero is illegal):


          var a = +this.getField("Text7").value;
          var b = +this.getField("Text5").value;
          if (b==0) event.value = "";
          else {
              var result = (a - 32) / (24 / b);
              if (result>=100) {
                  event.value = Math.round(result);
              } else event.value = util.printf("%,1 0.1f", result);