Описание тега parseint

NoneParseInt is a function that returns the integer representation of a given string.

parseInt is a function that returns the integer representation of a given string. It requires one parameter, but usually it can accept two parameters:

parseInt(toParse)
parseInt(toParse, radix)

Where toParse is a string, and radix is an integer. When the one-parameter function is called, a radix of 10 is used for the conversion.

In Javascript the syntax is parseInt(toParse, radix)Examples of use with:

document.write(parseInt("10") + "<br>");
document.write(parseInt("82", 16) + "<br>");
document.write(parseInt("11.25") + "<br>");
document.write(parseInt("23 11 55 32") + "<br>");
document.write(parseInt(" 7 ") + "<br>");
document.write(parseInt("45 programmers") + "<br>");
document.write(parseInt("I am 23") + "<br>");

Output:

10
130
11
23
7
45
NaN

In Java the syntax is Integer.parseInt(toParse, radix). Unlike javascript, with java you have to be sure that you try to parse an integer. Parsing 11.25, 23 11 55 32 or 45 programmers will fire a NumberFormatException.

Examples:

System.out.println(Integer.parseInt("10"));
System.out.println(Integer.parseInt("82", 16));
System.out.println(Integer.parseInt("11.25"));
System.out.println(Integer.parseInt("23 11 55 32"));
System.out.println(Integer.parseInt(" 7 "));
System.out.println(Integer.parseInt("45 programmers"));
System.out.println(Integer.parseInt("I am 23"));

Output:

10
130
Exception in thread "main" java.lang.NumberFormatException: For input string: "11.25"