It's because, according to the documentation, starting from the first non-whitespace character, an optional initial plus or minus sign (in this case, '+') followed by as many base-10 digits as possible (in this case, '-2'). The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

Obviously, "-2" is not a string of "base-10 digits", so it is interpreted as "additional characters", which are simply ignored.