Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FAQ Topic - Why does K = parseInt('09') set K to 0? (2013-05-20)

4 views
Skip to first unread message

FAQ server

unread,
May 19, 2013, 7:00:01 PM5/19/13
to
-----------------------------------------------------------------------
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------

Method `parseInt` generally needs a second parameter, `radix`,
for the base (from 2 to 36).

If `radix` is omitted, the base is determined by the contents of
the string. Any string beginning with `'0x'` or `'0X'` represents a
hexadecimal number. A string beginning with a leading 0 may be parsed as
octal (as if `raxix` were 8), in ECMA-262 Ed 3 (octal digits are `0-7`).
If string `'09'` is converted to `0`.

To force use of a particular base, use the `radix`
parameter: `parseInt("09", base)`.

<URL: http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt>
<URL: http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx>
<URL: http://docs.sun.com/source/816-6408-10/toplev.htm#1064173>
<URL: http://jibbering.com/faq/notes/type-conversion/#tcPrIntRx>


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

0 new messages