Simple formcalc Avg calculation default value issue | Community
Skip to main content
Level 3
February 7, 2022
Solved

Simple formcalc Avg calculation default value issue

  • February 7, 2022
  • 2 replies
  • 1911 views

I have a simple Avg FormCalc calculation below, but the default value is showing -0.01 and for the life of me I do not know why, and need some help.

 

Avg(pmp.Page8.D1, pmp.Page8.D2, pmp.Page8.D3, pmp.Page8.D4, pmp.Page8.D5, pmp.Page8.D6, pmp.Page8.D7, pmp.Page8.D8, pmp.Page8.D9, pmp.Page8.D10 ,pmp.Page8.D11, pmp.Page8.D12, pmp.Page8.D13, pmp.Page8.D14 ,pmp.Page8.D15 ,pmp.Page8.D16)

I even tried adding the following code to see if it would help, but didn't.

if (this.rawValue <= 0) this.rawValue = "";

The only other thing I did to this field was check the limit field box, and change the display pattern to "num{zzzz9.zz}"

 

Any help would be appreciated.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MHWinter

To round down, in FormCalc, you could use this formula:

round(NumericField1.rawValue + .005,2)-.01

2 replies

MHWinter
Level 4
February 7, 2022

I don't know why the avg function would return -0.01 as default, but I think the test you tried is scripted in JavaScript, not in FormCalc and I doubt you can mix both languages in the same event.

Level 3
February 8, 2022

I know the second piece of the code is javascript, but the top i did in formcalc.  its weird since the code @mayank_tiwari  has, is the same exact code i have in the calculate script, except for a few misplaced commas, which I fixed.  But, I found the issue where the second "overall score" field was also doing an average calculation for some reason, and once I took that out, it fixed the issue.

 

But now my issue is that the 2nd field, no matter what I do with javascript, is showing a 0 by default, but I want it to show blank, any ideas on this?

 

 

 

Mayank_Tiwari
Adobe Employee
Adobe Employee
February 8, 2022

Not sure what you are doing with your form. Anyway, I have fixed this as well.

Fixed Form: https://drive.google.com/file/d/1R8vEWeyIk_hqhC653vOYYiuAdBdncCz9/view?usp=sharing

 

Mayank_Tiwari
Adobe Employee
Adobe Employee
February 8, 2022
Level 3
February 9, 2022

So, I was testing the code for these drop down fields and I realized that is was rounding up to the 2nd decimal, for example 4.745 was displaying as 4.75.  So, I simply added - .005 to the end of the calculation, so now by default the field is displaying -0.01 by default.  I have been trying various codes for example:

if (this.rawValue != null) then
""
endif

I have tried a few other things like:

 

this.rawValue = PBoverall.value.toFixed(2)

but anything that I do to either set the default value as null or 0, ends up with the field not pulling the data from the field doing the calculation.

 

I'm really struggling with this here, because although the calculation works as expected when the fields are filled out, they do not want to have the default showing -0.01

MHWinter
MHWinterAccepted solution
Level 4
February 10, 2022

To round down, in FormCalc, you could use this formula:

round(NumericField1.rawValue + .005,2)-.01