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

Improve company productivity with a Business Account.Sign Up

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

Pravin AsarPrincipal Systems EngineerCommented:
alert (parseInt (0025));
alert (parseInt ('0042'));
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.
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);

Pravin AsarPrincipal Systems EngineerCommented:
Use this one...

function removeLeadZero (z) {
while (z.charAt(0)=="0")

// Case all 0
if (!z.length) { z="0"; }
return z;
alert (parseInt(removeLeadZero('0025')));
alert (parseInt(removeLeadZero('0042')));
alert (parseInt(removeLeadZero('000000')));
bemara57Author Commented:
AH HAH!!! Zvonko, thanks again. That was the problem
ZvonkoSystems architectCommented:
You are welcome.

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.