From: FAQ server on 28 May 2010 19:00 ----------------------------------------------------------------------- FAQ Topic - Why does K = parseInt('09') set K to 0? ----------------------------------------------------------------------- Method ` parseInt ` generally needs a second parameter, ` radix `, for the base (value between 2 and 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 (octal digits are ` 0-7 `). The string ` '09' ` is converted to ` 0 `. To force use of a particular base, use the ` radix ` parameter: ` parseInt("09", base) `. http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/parseInt http://msdn.microsoft.com/en-us/library/x53yedee%28VS.85%29.aspx http://docs.sun.com/source/816-6408-10/toplev.htm#1064173 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.
From: Dr J R Stockton on 30 May 2010 12:27 In comp.lang.javascript message <4c004afc$0$285$14726298(a)news.sunsite.dk >, Fri, 28 May 2010 23:00:03, FAQ server <javascript(a)dotinternet.be> posted: >Method ` parseInt ` generally needs a >second parameter, ` radix `, for the base (value between 2 and 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 (octal digits are ` 0-7 `). The string ` '09' ` >is converted to ` 0 `. Still inaccurate. It should say that, with no radix (or radix == undefined?), the characters which determine the base can be preceded by whitespace and/or sign. It should also say that interpreting "09" as 9 is <whatever ECMA 5 says>, but that only Opera (and ...?) complies. -- (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 7. Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links. Command-prompt MiniTrue is useful for viewing/searching/altering files. Free, DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.
|
Pages: 1 Prev: how to deliniate a currency-variable. Next: Load and display an image. |