Name
parseInt() — NN 2 IE J1 ECMA 1
Synopsis
parseInt(string
[, radix
])
Returns an integer value (as a number data type in base-10) of the
numerals in the string passed as a parameter. The string value must
at least begin with a numeral, or the result is
NaN
. If the string starts with numbers but changes
to letters along the way, only the leading numbers are converted to
the integer. Therefore, you can use the expression:
parseInt(navigator.appVersion)
to extract only the whole number of the version that leads the otherwise long string that is returned from that property.
The optional radix parameter lets you specify the base of the number
being passed to the function. A number string that begins with zero
is normally treated as an octal number, which gives you the wrong
answer. It is a good idea to use the radix value of 10 on all
parseInt()
functions if all of your dealings are
in base-10 numbers.
Returned Value
Integer of base-10.
Parameters
-
string
Any string that begins with one or more numerals.
-
radix
An integer of the number base of the number passed as the string parameter (e.g., 2, 10, 16).
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.