• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Round number from custom formula to 1 decimal

New Here ,
Apr 27, 2020 Apr 27, 2020

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!

TOPICS
Acrobat SDK and JavaScript

Views

317

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 27, 2020 Apr 27, 2020

Change this:

nSum/nCnt

To:

(nSum/nCnt).toFixed(1)

Votes

Translate

Translate
Community Expert ,
Apr 27, 2020 Apr 27, 2020

Copy link to clipboard

Copied

LATEST

Change this:

nSum/nCnt

To:

(nSum/nCnt).toFixed(1)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines