Copy link to clipboard
Copied
I have a form in which I am using the below custom calculation script:
// Acquire Inputs
var nA = Number(this.getField("Yes1").valueAsString);
var nB = Number(this.getField("TotalOSAudited").valueAsString);
var nSum = Number(this.getField("YesPerc1").valueAsString);
// Perform Calculation
var nSum = (nA / nB)*100;
// Assign Result to Field
event.value = nSum;
The select format category is None. I need the calculation to round to 2 decimal places ONLY. I have spent the last two days going cross eyed searching for the answer. I am a newby to any sort of script. Thanks for the help!
Copy link to clipboard
Copied
You also need to check that nB is not 0, or you will get NaN error because of trying to divide with zero.
To make two decimals, use like this:
event.value = nSum.toFixed(2);
Why do you declare var nSum to field "YesPerc1" and then also declare it again in calculation?