Skip to main content
Participant
August 23, 2018
Answered

Calculate Percentages.

  • August 23, 2018
  • 1 reply
  • 522 views

I have created quite a lengthy form with several simple calculations with no issues. But there is one that I am really struggling to resolve

I have 3 Input fields to generate 2 calculations as percentages, FieldE, FieldG & FieldH

FieldAA = FieldG/(FieldE*52)

FieldBB = (FieldG+FieldH)/(FieldE*52)

The issue is when entering field values;

If the AA & BB format is set to None, then I see NaN; if the are formatted to number (percentage) then I see the message; 'The value entered does not match the format of the field'.

I have spent some time combing through several threads on this but cannot seem to find an answer that works for me.

I've tried simple notation, custom calculations and custom format scripts; now not sure which I should be using!

I've several including:

FieldAA

var x = this.getField("FieldG");

var y = this.getField("FieldE"); 

if (y ==0)

{

event.value = "";

}

else

{

event.value = (x.value / (y.value * 52));

}

Any help would be massive thanks.

This topic has been closed for replies.
Correct answer try67

Use this code:

var x = Number(this.getField("FieldG").valueAsString);

var y = Number(this.getField("FieldE").valueAsString);

if (y==0) {

    event.value = "";

} else {

    event.value = (x / (y * 52));

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 23, 2018

Use this code:

var x = Number(this.getField("FieldG").valueAsString);

var y = Number(this.getField("FieldE").valueAsString);

if (y==0) {

    event.value = "";

} else {

    event.value = (x / (y * 52));

}

ngc2215Author
Participant
August 24, 2018

Thank You so much, that was spot on

I've now used your formula as a guide to fix the same issue with some more complicated calculations! They now all work .

Thanks Again