[thelist] javascript parseInt (TIP)

Chris at globet.com Chris at globet.com
Sat Sep 16 07:31:02 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;

And on the offchance that there's any more interest at all left in this
thread, any number beginning with 0x will be interpreted as hexadecimal.
Hence, the following all evaluate to 17:

parseInt("0x11")
parseInt("021")
parseInt(17)

[..]

-- 
Chris Marsh
Software Developer
t: +44 20 8246 4804 x828
f: +44 20 8246 4808
e: chris at globet.com
w: http://www.globet.com/

Any opinions expressed in this email are those of the individual and not
necessarily the Company. This message is intended for the use of the
individual or entity to which it is addressed and may contain
information that is confidential and privileged and exempt from
disclosure under applicable law. If the reader of this message is not
the intended recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly prohibited.
If you have received this communication in error, please contact the
sender immediately and delete it from your system. 



More information about the thelist mailing list