coder and technology lover
parseInt(): difference between Javascript and Actionscript
Today is the day of the little big discoveries. I realized that the parseInt() function, which objective is the same in both languages (Actionscript and Javascript), is a bit different between them. In Actionscript the function is based on base 10 numeration, in Javascript instead the funny thing is that it try to guess the radix by analyzing the string received as first argument, so if you want to be sure of the result returned you have to explicitly pass the radix in the second argument.
Example:
var myString = "000123"; alert(parseInt(myString));
The code above will alert 83 instead of 123 (because the default base guessed by Javascript isn’t 10 like in Actionscript), to get 123 the code must be:
var myString = "000123"; alert(parseInt(myString, 10));
| Print article | This entry was posted by Davide Zanotti on 6, Friday f, 2009 at 8:27 am, and is filed under actionscript, javascript. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |