Solved

Trying to convert 0025 into an integer.. Pls help!

Posted on 2006-11-06
7
272 Views
Last Modified: 2008-03-04
I'm grabbing a value from a database that returns numbers like 0025 or 0042. It really means 25 and 42. How do I put thos values into a javascript variable while letting it know that its an integer? Javascript doesn't like numbers with double zeros in front of it.  It returning 0025 as 21 for some reason. How do I convert 0025 to 25?
0
Comment
Question by:bemara57
[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
7 Comments
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 17884495
alert (parseInt (0025));
alert (parseInt ('0042'));
0
 
LVL 2

Expert Comment

by:ThijsS
ID: 17884549
If there are some numbers with decimals, use parseFloat(NumberFromDatabase). If there aren't any decimal numbers, just integers, use: parseInt(NumberFromDatabase) as in the comment above.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17884844
You have to put the radix as second parameter of the parseInt() method.
Like this:

var theNum = parseInt("0025", 10);

0
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!

 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 17884853
Oh, the default radix for numbers starting with zero is eight (octal numbers).

0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 17885017
Use this one...

function removeLeadZero (z) {
while (z.charAt(0)=="0")
{
z=z.substring(1,z.length);
}

// Case all 0
if (!z.length) { z="0"; }
return z;
}
alert (parseInt(removeLeadZero('0025')));
alert (parseInt(removeLeadZero('0042')));
alert (parseInt(removeLeadZero('000000')));
0
 

Author Comment

by:bemara57
ID: 17885446
AH HAH!!! Zvonko, thanks again. That was the problem
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17885452
You are welcome.

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

728 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