• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

isNumeric() returns true for "NaN"

Guest
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.
TOPICS
Advanced techniques

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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-valid-numeric...

For what it is worth, it returns "NO" with ColdFusion 8.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 06, 2008 Nov 06, 2008

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 07, 2008 Nov 07, 2008

Copy link to clipboard

Copied

LATEST
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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation