• Global community
• Language:
• Deutsch
• English
• EspaÃ±ol
• FranÃ§ais
• PortuguÃªs
• æ—¥æœ¬èªžã‚³ãƒŸãƒ¥ãƒ‹ãƒ†ã‚£
Dedicated community for Japanese speakers
• í•œêµ­ ì»¤ë®¤ë‹ˆí‹°
Dedicated community for Korean speakers
Exit
• Re: Need to reduce decimal places after averaging

Need to reduce decimal places after averaging

New Here ,
Feb 14, 2023 Feb 14, 2023

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

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

Change the last line to:

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

2 Replies 2
Community Expert ,
Feb 14, 2023 Feb 14, 2023

Copied

Change the last line to:

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

Report

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

Copied

LATEST

Much respects to you!

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