[thelist] parseInt in javascript

Mark Howells mark at mountain.ch
Mon Dec 24 03:55:37 CST 2001


>> From: "Richard Bennett" <richard.bennett at skynet.be>

>> What I wanted was 0-9 to have a leading 0, so all numbers had two digits:
>> 
>> pad = function(int) {
>>       return int=(int<10)?"0"+int:int
>> }
>> 
>> status=pad(3)
>> 
>> will show 03
>> 
> 
> Jeff C (jeffc33 at hotmail.com) wrote:
> 
> Be careful using parseInt() here.  If the string starts with a 0 it
> will be parsed as an octal number.

I've had a very odd result when parsing some numbers using parseInt, in my
case for checking whether a date was valid. I found that if you parseInt
"08" or "09" (strings from a form field), you get 0. (Other numbers from 1
to 100 seem to be OK; This is on Mac, if that makes a difference).

Regards
Mark Howells
Working in a Winter Wonderland
http://www.mark.ac







More information about the thelist mailing list