Solved

ParseInt("000008") returns 0.

Posted on 2004-04-15
5
282 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now