Copy link to clipboard
Copied
Its been a while since i have been into Java. I want to calculate a percentage but if the first number is zero then dont calculate. This is what I have so far:
var a=this.getField("CT-TPE");
var b=this.getField("CT-TPV");
var c=this.getField("PER.0.0");
c.value=(a.value/b.value);
Any help would be so appreciated.
Use this code, instead:
var a = Number(this.getField("CT-TPE").valueAsString);
var b = Number(this.getField("CT-TPV").valueAsString);
if (b==0) event.value = "";
else event.value=a/b;
Copy link to clipboard
Copied
You can't divide with zero. Also it's javascript not java.
Copy link to clipboard
Copied
Thank you for the clarification. The form will have a zero at times, so how do i create a formula that says if it a zero then ignore?
Copy link to clipboard
Copied
Do you know how i could do it if null?
Copy link to clipboard
Copied
Use this code, instead:
var a = Number(this.getField("CT-TPE").valueAsString);
var b = Number(this.getField("CT-TPV").valueAsString);
if (b==0) event.value = "";
else event.value=a/b;
Copy link to clipboard
Copied
That did it. Thank you so much!!!