0

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.

3
  • have you tried using int or uint instead of Number, just to see if it works? Commented May 27, 2011 at 4:32
  • Try putting lastDigit is Number in parenthesis like (lastDigit is Number). Does that work? Commented May 27, 2011 at 4:35
  • try with int(e.target.name.charAt(e.target.name.length-1)); Commented May 27, 2011 at 8:29

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so very much!! Too funny, my code would have worked had I tried but I psyched myself out thinking I had strings!! Such fun. Ya live and learn.
0
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.

1 Comment

Thank you very much! tracing 'lastDigit is Number) does trace true.
0

Use brackets around "lastDigit is Number":

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

which should give you lastDigit is number = true

Comments

0

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

Refer this.

5 Comments

1. Why delete and repost after I fix it? 2. This has nothing to do with the question..?
Is u want to convert last digit as number?
I don't know... what is your problem... My answer is relevent to your question... Is it or not?
Sorry bro, didn't mean to sound aggressive. Nice code but it's not the solution to the problem - he's trying to convert a string to a number not find all the numbers in the string.
@ Mr.Marty Wallace : I have changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.