3 Replies Latest reply on Nov 7, 2008 11:53 AM by gr8white

# isNumeric() returns true for &quot;NaN&quot;

According to the docs isNumeric(arg) returns "True, if arg can be converted to a number; otherwise False."

However (in CFMX7)
<cfset temp = "NaN">
<cfoutput>#isNumeric(temp)#</cfoutput> <!---outputs "YES"--->
<cfset temp = temp + 1> <!---generates error The value "NaN" cannot be converted to a number--->

So obviously something is wrong.
• ###### 1. Re: isNumeric() returns true for &quot;NaN&quot;
Yes, the "NAN" case is mentioned in the comments here.
http://www.coldfusioncookbook.com/entry/15/You-need-to-test-a-string-to-see-if-it-is-a-val id-numeric-value.

For what it is worth, it returns "NO" with ColdFusion 8.
• ###### 2. Re: isNumeric() returns true for &quot;NaN&quot;
Coldfusion MX7 is actually right! NaN is numeric in the same sense that infinity is numeric. MX7 is also right in saying that NaN, just like infinity, cannot be converted to a number. In fact, it cannot even be converted to itself! One definition of NaN is:

x is NaN if and only if (x = x) is false.

However, this makes arithmetic assumptions that fail in the real world of computers. CF8 gets it right. To avoid inconsistency in coding, IsNumeric("NaN") should return False.

• ###### 3. Re: isNumeric() returns true for &quot;NaN&quot;
I agree. The sole usefulness of the function for me is to determine whether a value can be converted to a number that CF recognizes as a number, not something that in mathematical theory is a number. I had to program a workaround when I got an unexpected error, not a big deal but still annoying.

Ken