7 Replies Latest reply on Jul 27, 2011 9:47 AM by Muriah Baker

# I need assistance removing 'NaN' as a result from a script.

I am attempting to do a simple a/b...thanks.

• ###### 1. Re: I need assistance removing 'NaN' as a result from a script.

It happens when the divisor is 0, which is an illegal operation.

You need to use a custom script to make sure that if that's the case, the

calculation doesn't take place.

• ###### 2. Re: I need assistance removing 'NaN' as a result from a script.

I realize a custom script is needed...I was hoping someone could provide that script...I am very new to JavaScript.

• ###### 3. Re: I need assistance removing 'NaN' as a result from a script.

Let's say your fields are actually named "a" and "b". Use this code as the custom calculation of the field in question:

event.value = "";
var a = getField("a").value;
var b = getField("b").value;

if (a!="" && Number(b)!=0) {
event.value = Number(a) / Number(b);
}

1 person found this helpful
• ###### 4. Re: I need assistance removing 'NaN' as a result from a script.

You need to test that each input is not a non-numeric value and that the dividend is not zero. A null string is treated as a zero numeric value. A divisor of zero, including a null character string, will always result in a value of zero, so there is no need to check this value for being zero. One needs to check that the dividend is not zero and that both the dividend and divisor are numeric values or not Not a Number.

var a = this.getField("a").value;
var b = this.getField("b").value;

event.value = "";
if ( isNaN(a) == false & isNaN(b) == false & Number(b)!= 0 ) {
event.value =  Number(a) / Number(b);
}

It is also possible that result could be expressed in scientific notation or be reported as number 'Infinity' or '-Infinity' either of which will also throw an error about the format not matching.

1 person found this helpful
• ###### 5. Re: I need assistance removing 'NaN' as a result from a script.

Thank you!

• ###### 6. Re: I need assistance removing 'NaN' as a result from a script.

Thank you

• ###### 7. Re: I need assistance removing 'NaN' as a result from a script.

This worked.