Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ParseInt("000008") returns 0.

Posted on 2004-04-15
5
285 Views
Last Modified: 2006-11-17
Dear all,

Can anybody tell me why parseInt("000007") returns 7, but parseInt("000008") returns 0, and parseInt("000011") returns 9? Do I need to write a function that strips the leading zero's? If so, does anybody have this function to hand?

Many thanks,

Ben.
0
Comment
Question by:webtechy
  • 2
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 250 total points
ID: 10833017
because if you begin a number with 0 it is parsed as an octal (base 8)

try this:  parseInt("000008",10)

0
 
LVL 33

Expert Comment

by:knightEknight
ID: 10833023
... which specifies the base as 10
0
 
LVL 2

Author Comment

by:webtechy
ID: 10833072
Excellent, thanks :-)
0
 
LVL 8

Expert Comment

by:HaydnH
ID: 10833129
0
 
LVL 2

Author Comment

by:webtechy
ID: 10833146
Thanks HaydnH, a favourite site of mine that - after knightEknight's comment I went there myself to take a look :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Index on a Table 6 25
innerHTML 7 34
Insert Button on a table 16 37
Do alert on select 6 13
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question