I was debugging some strange errors in a date conversion function I was writing, and I stumbled upon something that amazed me... a strange bug in
Clearly for the strings
parseInt fails to return the right value. One workaround is easy, use
Why does this happen and where should I report this? I find it extremely odd that it happens in both Firefox and Internet Explorer 6 & 7; there must be some explanation right?
Ok, Ok, so now that I explained how you would expect it to work (and clearly how I expected it to work) I'm going to answer my own question (yes I hate it when I do that too)
The problem is with how
parseInt guesses the base of your number. Read the parseInt spec. Instead of always defaulting to base 10, it tries to guess, and if the first character is '0' it thinks you want to parse as an octal number, and if it starts with '0x' it thinks you want hexadecimal.
So, the solution is either to use
parseFloat or to always specify your base.
Defaults that change on their own can't be trusted.