Reputation: 1
I'm trying to convert a string to number and no matter what I do, get strings still.
var lastDigit:Number = Number(e.target.name.charAt(e.target.name.length-1));
trace ('lastDigit is number = ' + lastDigit is Number)
And this traces false. I also tried parseInt and get a type coercion error.
Thanks in advance! I'm sure I'm overlooking something obvious.
Upvotes: 0
Views: 468
Reputation: 21
Use brackets around "lastDigit is Number":
trace ('lastDigit is number = ' + (lastDigit is Number))
which should give you lastDigit is number = true
Upvotes: 0
Reputation: 39456
trace ('lastDigit is number = ' + lastDigit is Number)
This is the same as:
var lastDigit:Number = 10;
var str:String = 'lastDigit is number = ' + lastDigit;
trace(str is Number);
You're checking if 'lastDigit is number = ' + lastDigit
is a number.
If you try,
trace(lastDigit is Number);
That shall work.
Upvotes: 0
Reputation: 451
this might help:
var bool:Boolean = lastDigit is Number;
trace(bool);
trace(lastDigit)
trace(typeof(lastDigit));
trace(...lastDigit is Number) is false because it is evaluated as a string in the trace statement
Upvotes: 2