int

Commons
stable

Thin wrapper around parseInt with a default radix of 10. Accepts both string and number inputs.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

value
required
string | number
The value to parse. Strings are parsed as integers; numbers are passed to parseInt directly.
radix
number
10
The base for the parseInt call. Defaults to 10 (decimal). Use 16 for hex strings.

API

Return value

The value returned by this util.

The parsed integer. Returns NaN for non-numeric input (same as parseInt behaviour).

Usage

Examples

Ready-to-paste usage snippets.

Parse integers from strings

typescript