F
FAQ server
-----------------------------------------------------------------------
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------
The parseInt function decides what base the number is by
looking at the number. It assumes that any number beginning
with '0x' or '0X' is hexadecimal, but it has a choice with a
leading zero: the number can either be octal or decimal.
Assuming octal, the string '09' will be converted to 0 (octal
digits are 0-7); assuming decimal, '09' will be converted to 9
(the leading zero is ignored).
To force use of a particular base, add a second parameter:
« parseInt("09",base) »
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthparseint.asp
http://docs.sun.com/source/816-6408-10/toplev.htm#1064173
http://www.jibbering.com/faq/faq_notes/faq_notes.html#FAQN4_12
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.
FAQ Topic - Why does K = parseInt('09') set K to 0?
-----------------------------------------------------------------------
The parseInt function decides what base the number is by
looking at the number. It assumes that any number beginning
with '0x' or '0X' is hexadecimal, but it has a choice with a
leading zero: the number can either be octal or decimal.
Assuming octal, the string '09' will be converted to 0 (octal
digits are 0-7); assuming decimal, '09' will be converted to 9
(the leading zero is ignored).
To force use of a particular base, add a second parameter:
« parseInt("09",base) »
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthparseint.asp
http://docs.sun.com/source/816-6408-10/toplev.htm#1064173
http://www.jibbering.com/faq/faq_notes/faq_notes.html#FAQN4_12
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.