Skip to main content
October 27, 2017
Question

Missing ; before statement

  • October 27, 2017
  • 1 reply
  • 1149 views

I have the following custom calculation script:

var average = this.getField("Text10").value;

var v = 0;

var fieldName = "fill"; //fields are named time.0, time.1, ...

var s = 0;

var sd = 0;

n = 6; //number of fields

for (var i = 0; i < n; i++) {

    v = this.getField(fieldName + i).value;

    s = s + Math.pow((v - average), 2);

}

sd = ((Math.sqrt(s / n)) / average); //standar deviation

event.value = sd;

event.value = util.printf("%.2f", event.value);

I want the display to be in percentage as opposed to a decimal.  I've tried to just multiply the sd function by 100, but keep getting "SyntaxError: missing ; before statement 13: at line 14.  I can't seem to get this formula correct.

Anyone help here, or is there a better way to display this as a percent?

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
October 27, 2017

Are you sure that's the exact code you're using, because I'm not getting this error message when I run it...

If you set the field's Format to Percentage and divide the final value by 100 then it should work.

October 27, 2017

Sorry for the confusion.  The one I posted does work.  The one that doesn't work would look like this:

var average = this.getField("Text10").value;

var v = 0;

var fieldName = "fill"; //fields are named time.0, time.1, ...

var s = 0;

var sd = 0;

n = 6; //number of fields

for (var i = 0; i < n; i++) {

    v = this.getField(fieldName + i).value;

    s = s + Math.pow((v - average), 2);

}

sd = ((Math.sqrt(s / n)) / average) * 100); //standar deviation

event.value = sd;

event.value = util.printf("%.2f", event.value);

October 27, 2017

nevermind.  I'm a little slow today.  I was missing a (