Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript: parseInt: Convert string to integer

parseInt(string, radix);
parseInt method takes a string and radix as arguments, and Convert the string to integer in given radix.

var a = parseInt("0377", 8); // Return 255
var b = parseInt("255", 10); // Return 255
var c = parseInt("0xff", 16); // Return 255

parseInt converts the Character by character, if it is unable to convert any character it ignores it and all succeeding characters, returns the integer value parsed up to that point.

var d = parseInt("123edf56", 10); // Return 123

If the first character cannot be converted to a number, parseInt returns NaN.

parseInt.html





parseInt



"text/javascript">
var a = parseInt("0377", 8); // Return 255
var b = parseInt("255", 10); // Return 255
var c = parseInt("0xff", 16); // Return 255

var d = parseInt("123edf56", 10); // Return 123
var e = parseInt("a1234", 10); // Return NaN

var f = parseInt("11111111", 2); // Return 255

document.write("a = " + a + "
"
);
document.write("b = " + b + "
"
);
document.write("c = " + c + "
"
);
document.write("d = " + d + "
"
);
document.write("e = " + e + "
"
);
document.write("f = " + f + "
"
);







Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

JavaScript: parseInt: Convert string to integer

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×