RE: [Flashcoders] Detecting NaN

2007-02-01 Thread Alain Rousseau
Simply use isNAN() method :
http://livedocs.macromedia.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhel
p.htm?context=LiveDocs_Partsfile=1737.html

if (isNAN(fooN)¨{
// do stuff
else {
// do else stuff
} 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Andy Herrman
Sent: 1 février 2007 12:12
To: Flashcoders
Subject: [Flashcoders] Detecting NaN

I'm trying to convert an arbitrary object into a Number, and then detect if
the conversion actually succeeded.  In theory I would convert it and then
check if the converted value is NaN, but this doesn't seem to work.

Here's my test.  In a blank FLA I put the following code:

--
var foo = foobar;
var fooN:Number = Number(foo);
trace(typeof(fooN));
if(fooN == NaN) {
trace(fooN is NaN);
} else {
trace(fooN is a number:  + fooN);
}
--

This should output:
number
fooN is NaN

but instead I get:
number
fooN is a number: NaN

For some reason the check to see if it's NaN isn't working, and I have no
idea why.

It looks like I can use isNaN(fooN) for the check instead, but I'm wondering
why == doesn't work.

   -Andy
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training http://www.figleaf.com
http://training.figleaf.com


--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.18/662 - Release Date: 2007-01-31
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.18/662 - Release Date: 2007-01-31
 

___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Re: [Flashcoders] Detecting NaN

2007-02-01 Thread Brandon Barkley

Andy,
Like the other poster said, us isNaN, but I was also curious about why 
this might be true.


I found this link on the subject that will be helpful (original page 
down): 
http://209.85.165.104/search?q=cache:ilnSqw-hBjwJ:livedocs.macromedia.com/flex/2/langref/package.html+Flash+NaN+equalityhl=engl=usct=clnkcd=3


The |*NaN*| value is not considered equal to any other value, including 
|*NaN*|, which makes it impossible to use the *equality* operator to 
test whether an expression is |*NaN*|. To determine whether a number is 
the |*NaN*| function, use |isNaN()|.


Brandon

-

I'm trying to convert an arbitrary object into a Number, and then
detect if the conversion actually succeeded.  In theory I would
convert it and then check if the converted value is NaN, but this
doesn't seem to work.

Here's my test.  In a blank FLA I put the following code:

--
var foo = foobar;
var fooN:Number = Number(foo);
trace(typeof(fooN));
if(fooN == NaN) {
   trace(fooN is NaN);
} else {
   trace(fooN is a number:  + fooN);
}
--

This should output:
number
fooN is NaN

but instead I get:
number
fooN is a number: NaN

For some reason the check to see if it's NaN isn't working, and I have
no idea why.

It looks like I can use isNaN(fooN) for the check instead, but I'm
wondering why == doesn't work.

 -Andy
___
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com