How to parseInt "09" into 9 ?
Thanks for the answer dude.
jessegavin
2010-09-21 21:41:07
+1
A:
parseInt("09",10);
returns 9 here.
It is odd.
alert(parseInt("09")); // shows 9. (tested with Opera 10)
JCasso
2009-10-09 17:54:49
@JonH: Right. Thanks for warning. Since he wrote string instead of String I was mistaken.
JCasso
2009-10-09 17:59:05
Depending on the browser and version parseInt("09") can return 0.It is a bug.
JonH
2009-10-09 18:34:05
@JonH: can you please check this: http://www.w3schools.com/jsref/jsref_parseInt.asp document.write(parseInt("010") also displays 10 here.
JCasso
2009-10-09 18:39:26
@JonH: It's not actually a bug. ECMAScript allows implementations to treat numbers with leading zeros as octal. Some implementations do, and some don't.
Matthew Crumley
2009-10-09 19:27:16