Despite the rather clear documentation which says that parseFloat() can return NaN as a value, when I write a block like:
if ( NaN == parseFloat(input.text) ) {
errorMessage.text = "Please enter a number."
}
I am warned that the comparison will always be false. And testing shows the warning to be correct.
Where is the corrected documentation, and how can I write this to work with AS3?
Because comparing anything to NaN is always false. Use isNaN() instead.
isNaN(parseFloat(input.text))
BTW, if for some reason you don't have access to isNaN(), the traditional method is to compare the number to itself:
if( number != number )
{
//Is NaN
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With