开发者

Help converting a string to number please

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.


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


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.


Use brackets around "lastDigit is Number":

trace ('lastDigit is number = ' + (lastDigit is Number))

which should give you lastDigit is number = true


http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f87.html

Refer this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜