I was troubled by a problem today. There is a page that runs fine on the browser (whether it is a mobile phone or a PC), but there is a problem through WebView. There are two worthy calculations that always go wrong. So I used alert to display this value, and found that it was much different from the result calculated on the browser. It was originally a positive number, but it became a negative number. After careful comparison, it was found that some of the numbers were erased, and these numbers were converted from strings through parseInt. The only difference between the erased values and other normal numbers is that they all start with 0, such as "04903", while other values are "90874". In this case, the reason is obvious. The JavaScript parseInt supported by WebView converts all strings starting with 0 to 0. Once the problem is solved, it will be easier. Just write a str2Int method to replace parseInt.
[javascript]
str2Int:function(str){
str = str.replace(/^0+/g, '');
if(str.length == 0){
return 0;
}
return parseInt(str);
}
str2Int:function(str){
str = str.replace(/^0+/g, '');
}
return parseInt(str);