javascript parseint function , everybody knows what it is.
but you know what
parseint ("07") returns?
parseint ("08") and return how much?
The correct answer is
parseint ("07") returns 8
parseint ("08") returns 0
you know where the problem is?
In fact, this question may not have been thought of by everyone.
When using JavaScript's parseint function,
parseint ("08") or parseint ("09") returned is actually 0,
and parseint ("" ") ... parseint (" 07 ") are all right.
Why is this?
was difficult to understand at first, and later found that the problem was that when "0" was in front,
JavaScript's debugger would think of it as an octal number
and "08" and "09" were not a valid octal number,
This causes the problem, but parsefloat does not exist. The parseint () function in the
JavaScript Reference is described as follows:
parseint Method
Returns an integer converted from a string. Converts a string to an integer type.
parseint (numstring, [radix])
parseint parameters Radix :
available options. The value between 2 and 36 represents the numstring of the saved number. If not provided, the string prefixed with ' 0x ' is treated as hexadecimal, and the string prefixed with ' 0 ' is treated as an octal. All other strings are considered to be decimal.
Therefore, if you use parseint ("08", 10) or parseint ("$"),
notifies the JavaScript interpreter to use decimal to parse to get the number you want.
Attached:
parseint ("abc") //Return NaN.
parseint ("12ABC")//return 12.
As shown in the picture Carousel, when clicking on the image Number link, the innerHTML value in the link is converted to decimal integer number.
The use of parseint functions in JavaScript