Function Effect:
Parseint Converts a string (string) type to an integer type.
The number () function converts the value of the object to numbers.
Different syntax:
parseint (string, [radix])
String: The required number of parameters. The string to be converted
Radix: Optional, the cardinality of the number. The value range is 2~36.
Assume that the number of references is less than 2 or greater than 36. Then parseint () will return NaN.
<pre name= "Code" class= "JavaScript" > alert ("ParseInt1 return" + parseint ("1", 1)); Returns nan alert ("parseint0x123" + parseint ("0x123")); 291 alert ("parseInt000123" + parseint ("000123")); 123
When the value of the radix is 0, or if the parameter is not set, parseint () infers the cardinality of the number based on string.
Assuming that string starts with "0x", parseint () resolves the remainder of the string to a 16-binary integer.
Assuming that string starts with 0, then ECMAScript V3 agrees that an implementation of parseint () parses the subsequent character into octal or hexadecimal digits.
Suppose that string starts with a number from 1 to 9, and parseint () parses it into a decimal integer.
Number (object)
number returns a digit whose number is the object.
Assume that the value of an object cannot be converted to a number. Then the number () function returns NaN.
var test = new Date () var teststr = new String ("123"); var testStr1 = new String ("5,000"); Alert ("Number (test)" + number (test)); Returns 1437631091369 alert ("Number (TESTSTR)" + number (TESTSTR)); Returns 123 alert ("Number (TESTSTR1)" + number (TESTSTR1)); Return Nan
in var testStr1 = new String ("5,000"), the string contains a thousand character. This causes the conversion to be impossible. Although it is very small in detail, it should be cautious.
Contains thousands of characters of the string, can not be directly converted, the first to remove the thousand character, and then the conversion, this is the result of this blog.
parseint and number functions in JavaScript