|
-
Jun 28th, 2002, 04:02 AM
#1
Thread Starter
Fanatic Member
parseInt('08') returns 0
Hi,
I am having a real problem with this. I want to convert a string '08' to an integer 8, but the parseInt function seems to return 0 for this string... It also seems to do the same with '09'.
All values less than 8 work fine though .. ?
Does anyone know of a function that converts these strings correctly?
-
Jun 28th, 2002, 07:52 AM
#2
Hyperactive Member
you can try using eval() but I am not sure if that is the best
way but it seems to be working.
<html>
<head>
<title></title>
</head>
<body>
<script>
var a = '08';
var b = eval('08');
b = b * 2
document.write(b);
</script>
</body>
</html>
regards
bsw2112
-
Jun 28th, 2002, 09:13 AM
#3
Fanatic Member
bsw2112 you are correct, infact if you wanted to really test your number you could use parseInt(eval('08')) which will make whatever is in the quotes a number and then force it as an integer.
-Matt
-
Jul 1st, 2002, 12:53 AM
#4
Thread Starter
Fanatic Member
Thats all good and well, but why does this happen. It should convert to integer
-
Jul 10th, 2002, 05:48 PM
#5
New Member
Originally posted by cpradio
bsw2112 you are correct, infact if you wanted to really test your number you could use parseInt(eval('08')) which will make whatever is in the quotes a number and then force it as an integer.
-Matt
The problem is because 08 is not a number, and parseInt() returns the first thing it could find that resembles one. 0 is a number to it, but 08 is not, so it returns 0
-
Jul 11th, 2002, 01:03 AM
#6
Thread Starter
Fanatic Member
I'm confused. If it does not see '08' as a number, why does it see '07' as the number 7?
-
Jul 11th, 2002, 05:30 PM
#7
New Member
Hmmm...if that's the case I have no idea why. My guess is perhaps 07 is a special keyword/identifier. It seems other numbers like 09 also return 0, not 9.
-
Jul 12th, 2002, 02:01 AM
#8
Thread Starter
Fanatic Member
actually, all the numers '00' -> '07' return their true number eg. 1, 2 etc. It is only '08' and '09' that seem to have a problem with parseInt()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|