2 Replies Latest reply on Jan 23, 2014 9:00 AM by WesCD

    Issue rounding result to 2 decimal places


      Good day all,


      I currently have a format script to get the average of 10 fields on my form that also skips empty fields. Here is my current script:


      // Initialize variables

      var num = 0;

      var sum = 0;



      // Check input fields

      for (var i = 1; i < 10; i++) {

      var f = getField("Assesment_Rating" + i);

      if (f.valueAsString) {

      // increment the non-blank field counter


      // add the field value to the running total

      sum += +f.value;




      // Calculate the average

      if (num) {

      event.value = sum / num;

      } else {

      // If fields are empty, so set to blank

      event.value = "";   




      As it currently works if I have a total of 1.4444444444444, that is what is displayed. I've tried a couple of Math.Round functions that give me "1.5" as a result which is not correct. I'm still learning so I may have tried a Math.Round function in the wrong part of my code, but cannot get the result I need.



      Thanks in advance for your assistance!