get '09' to = 9

# Thread: get '09' to = 9

1. me
Senior Member
Join Date
Dec 1969
Posts
428

## get '09' to = 9

Does anyone know a quick way to get &#039;09&#039; to equal 9. I tried to parseInt and I get 0.<BR><BR>I am using this to format time so the string is sometimes both digits.<BR><BR>Is this the only way:<BR>if length similiar to 2 and parseInt(time) = 0 <BR> remove 0 and use second digit

2. Senior Member
Join Date
Dec 1969
Posts
228

## Number() or eval()

var myVar = &#039;09&#039;<BR><BR>return Number(myVar) == 9<BR><BR>OR<BR><BR>return (eval(myVar) == 9)

3. Senior Member
Join Date
Dec 1969
Posts
273

## RE: get '09' to = 9

you can use parseInt but you need to specify the radix otherwise it treats it as octal and doesn&#039;t work because 9 is not a valid octal digit. so...<BR><BR>parseInt(&#039;09&#039;) = 0<BR><BR>while...<BR><BR>parseInt(&#039;09&#039;,1 0) = 9

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•