Solved

ParseInt("000008") returns 0.

Posted on 2004-04-15
5
288 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

688 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