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

Need to reduce decimal places after averaging

New Here ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Hello, I am looking to reduce the number of decimal places after averaging. 

The average that I calculated 3+1+1 is 1.666666666666667

and it is displaying that answer, but what I would like is that after adobe calculates the average, it will only give me two decimal places. 1.67

 

This is the code that I am using: 

 

var nSum = 0; nCnt = 0;

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

{

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

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

{

nCnt++;

nSum += nVal;

{

}
event.value = (nCnt > 0)?nSum/nCnt:"N/A";

 

After I input 

then event.value =(util.printf("%0.2f",nVal));

 

I am no longer able to change the average 

 

Can you please help me calculate an overall average and them reduce my results to two decimal places

 

TOPICS
Windows

Views

395

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 , Feb 14, 2023 Feb 14, 2023

Change the last line to:

event.value = (nCnt > 0)?(nSum/nCnt).toFixed(2):"N/A";

Votes

Translate

Translate
Community Expert ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

Change the last line to:

event.value = (nCnt > 0)?(nSum/nCnt).toFixed(2):"N/A";

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
New Here ,
Feb 14, 2023 Feb 14, 2023

Copy link to clipboard

Copied

LATEST

Much respects to you! 

thank you, I am pretty new at this and its my first ever attempt at Javascript 

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