JavaScript parseInt() Function

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP







<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]
-->



JavaScript parseInt() Function


❮ JavaScript Global Functions



Example


Parse different strings:



var a = parseInt("10") + "<br>";
var b = parseInt("10.00") + "<br>";

var c = parseInt("10.33") + "<br>";
var d = parseInt("34 45 66") + "<br>";

var e = parseInt(" 60 ") + "<br>";
var f = parseInt("40 years") + "<br>";

var g = parseInt("He was 40") + "<br>";

var h = parseInt("10", 10)+ "<br>";

var i = parseInt("010")+ "<br>";
var j = parseInt("10", 8)+ "<br>";
var k = parseInt("0x10")+ "<br>";
var l = parseInt("10", 16)+ "<br>";


var n = a + b + c + d + e + f + g + "<br>" + h + i + j + k +l;

<!--

The result of n will be:




document.write(parseInt("10") + "
");
document.write(parseInt("10.00") + "
");
document.write(parseInt("10.33") + "
");
document.write(parseInt("34 45 66") + "
");
document.write(parseInt(" 60 ") + "
");
document.write(parseInt("40 years") + "
");
document.write(parseInt("He was 40") + "
");
document.write("
");
document.write(parseInt("10",10) + "
");
document.write(parseInt("010") + "
");
document.write(parseInt("10",8) + "
");
document.write(parseInt("0x10") + "
");
document.write(parseInt("10",16) + "
");

-->
Try it Yourself »


Definition and Usage


The parseInt() function parses a string and returns an integer.


The radix parameter is used to specify which numeral system to be used, for
example, a radix of 16 (hexadecimal) indicates that the number in the string
should be parsed from a hexadecimal number to a decimal number.



If the radix parameter is omitted, JavaScript assumes the
following:



  • If the string begins with "0x", the radix is 16 (hexadecimal)

  • If the string begins with "0", the radix is 8 (octal). This
    feature is deprecated

  • If the string begins with any other value, the radix is 10 (decimal)

Note: Only the first number in the string is returned!


Note: Leading and trailing spaces are allowed.


Note: If the first character cannot be converted to a number,
parseInt() returns NaN.


Note: Older browsers will result parseInt("010") as 8,
because older versions of ECMAScript, (older than ECMAScript 5, uses the octal
radix (8) as default when the string begins with "0". As of ECMAScript 5, the default is the decimal radix (10).






<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]
-->




Browser Support














Function
parseInt() Yes Yes Yes Yes Yes

Syntax



parseInt(string, radix)

Parameter Values







Parameter Description
string Required. The string to be parsed
radix Optional. A number (from 2 to 36) that represents the numeral system to be used

Technical Details






Return Value: A Number. If the first character cannot be converted to a number, NaN is returned
JavaScript Version: ECMAScript 1


❮ JavaScript Global Functions

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế