Skip to main content
Participant
April 27, 2020
Answered

Round number from custom formula to 1 decimal

  • April 27, 2020
  • 1 reply
  • 479 views

I am new to Adobe Acrobat and am creating a form to calculate the average of a selection of boxes titled Ratings. My form needs to automatically calculate the average without counting boxes that have not been filled out. I looked through this community and was able to find a working formula I could adjust to fit my needs. The formula works great, but now I can't figure out how to tell the formula to calculate the average only down to one decimal point--so instead of getting 3.333333 repeating sometimes, I would like to see only 3.3. The formula I am using is this:

 

var nSum = 0; nCnt = 0;

 

for(var i=5;i<=10;i++)

 

{

 

    var nVal = this.getField("Rating" + "_" + i).value;

 

    if(!/^\s*$/.test(nVal) && !isNaN(nVal))

 

    {

 

        nCnt++;

 

        nSum += nVal;

 

     }

 

}

 


event.value = (nCnt > 0)?nSum/nCnt:"-";

 

How would I be able to adjust the formula to fit my needs? Thank you in advance!

This topic has been closed for replies.
Correct answer try67

Change this:

nSum/nCnt

To:

(nSum/nCnt).toFixed(1)

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 27, 2020

Change this:

nSum/nCnt

To:

(nSum/nCnt).toFixed(1)