A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-number-parseint-method/ below:

JavaScript Number parseInt() Method - GeeksforGeeks

JavaScript Number parseInt() Method

Last Updated : 11 Jul, 2025

TheparseInt method parses a value as a string and returns the first integer. It accepts a string argument and optional radix parameter, defining the numeral system base. This method is commonly used for converting string representations of numbers into integers.

Example:

The method takes two parameters: the string to be parsed and the radix (optional, default is 10).
2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal.

Syntax

parseInt(Value, radix);

Parameters

Return value

It returns a number and if the first character can't be converted to a number then the function returns NaN. It returns a number parsed up to that point where it encounters a character that is not a number in the specified radix(base). 

Example 1: Parsing float value

Here, we are using the parseInt() method to parse the given float value.

javascript
let v1 = parseInt("3.14");
console.log('Using parseInt("3.14") = '+ v1);

Output
Using parseInt("3.14") = 3

Example 2: Parsing value with given radix

Here, we will also mention radix with the number.

javascript
// Base 10
a = parseInt("100", 10);
console.log('parseInt("100",10) = ' +
    a);

// Base 8
b = parseInt("8", 8);
console.log('parseInt("8",8) = ' +
    b);

// Base 8
c = parseInt("15", 8);
console.log('parseInt("15",8) = ' +
    c);

// Base 16
d = parseInt("16", 16);
console.log('parseInt("16",16) = ' +
    d);

// Leading and trailing spaces are ignored
// in parseInt() function
e = parseInt(" 100 ");
console.log('parseInt(" 100 ") = ' +
    e);

// Base 16(hexadecimal)
f = parseInt("0x16");
console.log('parseInt("0x16") = ' +
    f);

Output
parseInt("100",10) = 100
parseInt("8",8) = NaN
parseInt("15",8) = 13
parseInt("16",16) = 22
parseInt(" 100 ") = 100
parseInt("0x16") = 22

We have a complete list of JavaScript Number constructor, properties, and methods list, to know more about the numbers please go through that article.

Supported Browsers

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4