Original: JavaScript parseint () toString () function
parseint (string, radix)
String: Required. The string to be parsed
Radix: Optional. Represents the cardinality of the number to parse. The value is between 2 and 36.
If this argument is omitted or its value is 0, the number is parsed based on 10. If it starts with "0x" or "0X", it will have a base of 16.
If the parameter is less than 2 or greater than 36, parseint () returns NaN.
return value
Returns the parsed number.
Description
When the value of the parameter radix is 0, or if the parameter is not set, parseint () determines the cardinality of the number based on string .
For example, if string starts with "0x", parseint () resolves the remainder of the string to a 16-binary integer. If string starts with 0, then ECMAScript V3 allows an implementation of parseint () to parse subsequent characters into octal or hexadecimal digits. If string starts with a number from 1 to 9, parseint () parses it into a decimal integer.
parseint ("ten"); // returnto parseint ("+", "ten"); // returned (10+9)parseint ("One", 2); // returns 3 (2+1)parseint ("n", 8); // return to (8+7)parseint ("1f", +); // return to (16+15)parseint ("010"); // undecided: Returns 10 or 8
ToString () function
The 3 primary primitive types, Boolean, number, and string, have the ToString () method to convert their values into strings. All objects have the toString () method, whether it is a pseudo object or a true object. Because the String type belongs to a pseudo-object, it must have the toString () method.
The ToString () method of the Boolean type simply outputs "true" or "false", and the result is determined by the value of the variable:
var false ; alert (bfound.tostring ());//Output "false"
The ToString () method of number type is special, and it has two modes, the default mode and the base mode . With the default mode, the ToString () method simply outputs a numeric value (whether integer, floating point, or scientific notation) with the corresponding string, as follows:
var iNum1 = ten; var iNum2 = 10.0; alert (inum1.tostring ()); // output "Ten"Alert (inum2.tostring ()); // output "Ten"
Note: In the default mode, the ToString () method of number type returns a decimal representation of the numbers, regardless of what notation was originally used to declare numbers. Therefore, the output of a number declared in the form of eight hexadecimal literals is in decimal form.
The base mode of the ToString () method with the number type can be used with different base output numbers, such as the binary base is 2, the octal base is 8, and the hexadecimal base is 16.
base is just another addition to the cardinality to be converted, which is the parameter of the ToString () method:
var iNum = ten; alert (inum.tostring (2)); // output "1010"Alert (inum.tostring (8)); // output "a" alert (inum.tostring ()); // output "A"
Note: calling ToString (10) on a number is the same as calling ToString (), and they return the decimal form of the number.
Arrayobject.tostring (): The ToString () method converts an array to a string and returns the result.
<script type= "Text/javascript" >varnew Array (3) arr[0] = "George"arr[1] = " John "arr[2] =" Thomas "document.write (arr.tostring ())</script>
George,john,thoma
Booleanobject.tostring (): The ToString () method converts a logical value to a string and returns the result. Returns the string "true" or "false" based on the original Boolean value or the value of the Booleanobject object.
<script type= "Text/javascript" > varnew Boolean (true) document.write ( Boo.tostring ())</script>
True
Numberobject.tostring (): The ToString () method converts a Number object to a string and returns the result.
<script type= "Text/javascript" >varnew number (1337);d ocument.write (number.tostring ()) </script>
1337
Stringobject.tostring (): The ToString () method returns a string.
JavaScript parseint () toString () function