//Check the money format$ (". Text_money"). On ("Blur",function () { $( This). Val ($.isnumeric ($ ( This). Val ())? $( This). Val (): 0); }); //Check the number format$ (". Text_number"). On ("Blur",function () { $( This). Val ($.isnumeric ($ ( This). Val ())? $( This). Val (): 0); $( This). Val (parseint ($ ( This). Val ())); });
The parseint () parseint () method first looks at the character at position 0, determines if it is a valid number, and if not, the method returns Nan, and no further action is taken. However, if the character is a valid number, the method will look at the character at position 1 and perform the same test. This process continues until a character is found that is not a valid number, at which point the parseint () converts the string before the character to a number. For example, if you want to put a string"1234blue"is converted to an integer, then parseint () returns 1234, because when it detects the character B, it stops the detection process. The parseint () method also has a base mode that converts binary, octal, hexadecimal, or any other binary string into integers. The base is specified by the second parameter of the parseint () method, so the hexadecimal value is parsed, and, of course, the parseint () method can be called for binary, octal, or even decimal (the default mode). If the decimal number contains a leading 0, it is best to use cardinality 10 so that the octal value is not unexpectedly obtained. Instance of JScript code replication parseint ("1234blue");//return 1234parseint ("22.5");//return 22 The decimal point is an invalid character for integersparseint ("Blue");//return NaN//the parseint () method also has a base mode that converts binary, octal, hexadecimal, or any other binary string into integers. A base is specified by the second parameter of the parseint () method. //For example:parseint ("AF", 16);//return 1756 binaryparseint ("10", 2);//return 22 binaryparseint ("10", 8);//return 88 binaryparseint ("10", 10);//return 100 binary //If the decimal number contains a leading 0, it is best to use cardinality 10 so that the octal value is not unexpectedly obtained. //For example:parseint ("010");//return 8parseint ("010", 8);//return 8parseint ("010", 10);//return tenthe parsefloat () is similar to the parseint () method, viewing each character starting at position 0 until the first non-valid character is found, and then converting the string before the character to a number. However, for this method, the first decimal point that appears is a valid character. If there are two decimal points, the second decimal point is considered invalid, and the Parsefloat () method converts the string before the decimal point to a number. This means that the string"22.34.5" will be parsed into 22.34. Another difference between using the Parsefloat () method is that the string must represent a floating-point number in decimal form, not in octal or hexadecimal form. The method ignores the leading 0, so the octal number 0908 is parsed to 908. For hexadecimal 0xA, the method returns Nan because, in a floating-point number, X is not a valid character. In addition, parsefloat () has no base mode. For example, JScript code replication parsefloat ("1234blue");//return 1234.0parsefloat ("22.34.5");//return 22.34parsefloat ("0908");//return 908parsefloat ("Blue");//return NaN
The difference between parseint () and parsefloat ()