Java is an Integer. The parseInt () method, but the JavaScript parseInt handling and strong Integer such as Java language is different, so people often because of the improper use of this method and abnormal return.

the following is a Java code, for 020 a String to Integer.

public class Test {
public static void main (String args []) throws the Exception {
String STR="020";
System. Out. Println (Integer. The parseInt (STR));


the output is 20

here is a JavaScript code, is also the string into an integer 020.

var STR="020";
var num=parseInt (STR);
alert (num);

the output is 16

whether Java or JavaScript, parseInt method has two parameters, the first parameter is to convert objects, the second parameter is the base base, can be 2, 8, 10, 16, the default to decimal processing. But in JavaScript, 0 8 hexadecimal number is considered to use processing, 0 x number of hexadecimal is considered to be used to deal with. So the JavaScript code above calculation errors.

big impact?
big! Very big! Because this often is used to calculate the price, once the price is wrong, for the user, this is misleading, and a good website should not appear this kind of misleading. The following DEMO, not specified into the system. You can enter a starting with 0 in the number of box, click the calculate button, the calculated value will be smaller than expected, or much smaller (such as: no 019 in 8 hexadecimal values, so the numerical into 1, 9 overlooked).
no specifies the base for the parseInt function DEMO

how to modify?
said earlier, there are two parameters, the second parameter to specify the calculation using hexadecimal.

parseInt (num, radix);

so we can be there is problem in front of the JavaScript code for the following code.

var STR="020";
var num=parseInt (STR, 10);
alert (num);

this kind of treatment, we rewrite some DEMO, in front of the following:
as the parseInt function specifies the base for 10 DEMO
remember, on the JavaScript to bring better system parameters when using parseInt method.

This concludes the body part