[thelist] javascript parseInt (TIP)

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Sat Sep 16 06:42:51 CDT 2006


>
> In addition to Sam's tip to *always add the radix when using
> parseInt()* you can also use a shortcut when dealing with decimals.
> +"08" will return 8
>
>
For the interested parseInt("08") returns 0 because interpreter thinks that
"08" is octal;

8 Mod 8 => 0

Likewise, parseInt("0111") will return 11 Mod 8 = 1*64 + 1*8 + 1= 73

And, as Christian has mentioned, always using radix is a good practice of
defensive coding .

Cheers
-- 
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/cre8/blog/
+> Going solo in Turkish: http://www.volkanozcelik.com/donkisot/
+> My projects/studies/trials/errors : http://www.sarmal.com/
+> Sardalya JavaScript Library: http://www.sarmal.com/sardalya/



More information about the thelist mailing list