Copy link to clipboard
Copied
I have the following simple script in Custom calculation script in a Text Field called AS QUOTED CM%.
When the PDF Form has yet to be populated the AS QUOTED PROFIT field is $0 & the AS QUOTED TOTAL field is blank which creates a NaN answer. I want the calculated As QUOTED CM% field to be formated for Percent but I always get an error during use which will confuse the users.
How can I create an if NaN then 0 statement which I believe will resolve ther error
event.value =
(this.getField("AS QUOTED PROFIT").value/this.getField("AS QUOTED TOTAL").value)
;
Copy link to clipboard
Copied
Check that "AS QUOTED TOTAL" is not 0 because you can't divide by zero, something like this:
if(this.getField("AS QUOTED TOTAL").value != 0)
event.value =
(this.getField("AS QUOTED PROFIT").value/this.getField("AS QUOTED TOTAL").value)
;
Copy link to clipboard
Copied
Dividing by zero returns Infinity. When a field formatted as a number returns something other than a number it will display NaN ("Not a Number"). If you add the following script to the end of your script it will not only elimate the NaN display, but it will allow you to format the field as a percent and avoid popup "The value entered does not match the format..." errors:
if(event.value=="Infinity" || event.value=="NaN"){event.value=""}