Jump to content

Probelm with parseInt()


Recommended Posts

I have found this in an offline JS documentation I have:

If the radix is not specified or is specified as 0, JavaScript assumes the following:- If the input string begins with "0x", the radix is 16 (hexadecimal).- If the input string begins with "0", the radix is eight (octal). This feature is deprecated. - If the input string begins with any other value, the radix is 10 (decimal).
The string '08' begins with 0 and there is no radix specified, JS will think that all what is after the first 0 should be an octal number. But there is no 8 in the octal system (only 0-7), so the function returns 0.The solution is:parseInt(temp,10)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...