Skip to main content
Participant
January 11, 2018
Answered

How to I divide the amount in box 1 with box 2 and then show the percentage in box 3?

  • January 11, 2018
  • 1 reply
  • 808 views

How to I divide the amount in box 1 with box 2 and then show the percentage in box 3? 

This topic has been closed for replies.
Correct answer try67

Use this code as the custom calculation script of "Box 3":

var v1 = Number(this.getField("Box 1").valueAsString);

var v2 = Number(this.getField("Box 2").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 11, 2018

Use this code as the custom calculation script of "Box 3":

var v1 = Number(this.getField("Box 1").valueAsString);

var v2 = Number(this.getField("Box 2").valueAsString);

if (v2==0) event.value = "";

else event.value = v1/v2;

Participant
January 11, 2018

If 1 put 100$ in box 1 and in box 2 I get 100% in variance. isnt it suppose to be 0? also is there a way to ge the % in negative if need be?

try67
Community Expert
Community Expert
January 11, 2018

No. 100 out of 100 is 100%... If you want it to be zero then you need to calculate the reverse, like this:

else event.value = 1-(v1/v2);

Then if the second value is smaller than the first one, the result will be negative.