Copy link to clipboard
Copied
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!
Change this:
nSum/nCnt
To:
(nSum/nCnt).toFixed(1)
Copy link to clipboard
Copied
Change this:
nSum/nCnt
To:
(nSum/nCnt).toFixed(1)