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

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?
bemara57Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ZvonkoConnect With a Mentor Systems architectCommented:
Oh, the default radix for numbers starting with zero is eight (octal numbers).

0
 
Pravin AsarPrincipal Systems EngineerCommented:
alert (parseInt (0025));
alert (parseInt ('0042'));
0
 
ThijsSCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ZvonkoSystems architectCommented:
You have to put the radix as second parameter of the parseInt() method.
Like this:

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

0
 
Pravin AsarPrincipal Systems EngineerCommented:
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
 
bemara57Author Commented:
AH HAH!!! Zvonko, thanks again. That was the problem
0
 
ZvonkoSystems architectCommented:
You are welcome.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.