This article mainly introduces how to solve the incorrect parseInt function conversion problem in the WebView of Android, because the converted string numbers all start with 0, as a result, the parseInt function has different conversion results in the browser and AndroidWebView. This article provides a solution. if you need it, you can refer to the problem that is plagued today, one page runs well on the browser (whether it is a mobile phone or a PC), but there is a problem through WebView, and there are two worthy of computing errors. Then, through alert, this value is displayed, and it is found that the calculation result is much different from that on the browser. Originally, it is a positive number, but it turns into a negative number. After careful comparison, we find that some of the numbers are erased, and these numbers are converted from strings through parseInt. The only difference between erased values and other normal numbers is that they all start with 0, for example, "04903", while other values are "90874 ". The reason is obvious. the JavaScript parseInt supported by WebView converts all strings starting with 0 to 0. It is easier to solve the problem. you can write a str2Int method instead of parseInt.
The code is as follows:
Str2Int: function (str ){
Str = str. replace (/^ 0 +/g ,'');
If (str. length = 0 ){
Return 0;
}
Return parseInt (str );
}