Name
parseInt — Convert a string to an integer
Usage
Lang.parseInt(str)
: Stringstr
Description
Attempts to parse the string str
as a
decimal integer. A leading +
or
-
may be included; any spaces at the start of the
string are ignored, as are any characters at the end that can’t
be parsed as part of the integer.
If str
can’t be parsed as an
integer, returns invalid
.
Examples
Lang.parseInt("17")
returns integer 17
Lang.parseInt("23.67")
returns integer 23
Lang.parseInt(" -63 percent")
returns integer -63
Lang.parseInt("+4inches")
returns integer 4
Lang.parseInt(true)
returns invalid
Lang.parseInt(".3")
returns invalid
Lang.parseInt("+")
returns invalid
Get Learning WML, and WMLScript 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.