4 Replies Latest reply on Jul 18, 2017 4:24 PM by anas003

    Round Up

    anas003 Level 1


      how to round up a field

      for example filed 'ex' = 4.5

      rounded = 5

        • 1. Re: Round Up
          try67 MVP & Adobe Community Professional

          Add this code as the field's custom calculation script:


          if (event.value) event.value = Math.ceil(event.value);

          • 2. Re: Round Up
            anas003 Level 1

            no I have the result on a field

            and I want to round it up on another field

            • 3. Re: Round Up
              gkaiseril MVP & Adobe Community Professional

              If the value were 5.4 would you want that value rounded up to the next integer?


              Setting the field's format "Number" and setting the desired number of decimal places will cause the displayed result to be rounded up but will not change the value of the field.


              To change the value of field one must use a user written rounding routine. Most likely one would use this in a Custom JavaScript calculation.


              One can use the util.printf() method to round a calculation to a desired number of decimal places.


              // round the focused field to no decimal places;

              var nDec = 0; // variable to use for the number of decimal places to round to. in this case none or zero;

              event.value = Number(util.printf("%,101." + nDec + "f", event.value);


              D.P. Story has a much more robust function that can round to whole numbers or decimals with rounding.

              • 4. Re: Round Up
                anas003 Level 1

                I found the solution

                thank you

                event.value = Math.ceil(this.getField("Field1").value);