I. Numerical Conversion
Number (), parseint (), and parsefloat ()
1. Number () function conversion rules: applicable to any data type.
Boolean values true and false are converted to 1 and 0 respectively;
The value is just a simple graph transfer and return;
Convert null to 0;
Undefined to Nan;
Conversion rules when the target is a string:
A string contains only numbers and is converted to a decimal value. Leading 0 is ignored (including octal values, because octal values are composed of leading 0 and other numbers ranging from 0 to 7 );
The string contains valid floating point values and is converted to the corresponding floating point number;
The string contains valid hexadecimal numbers, which are converted to equal decimal values;
Convert an empty string to 0;
2. parseint () Conversion Function, dedicated to strings
Conversion rules:
This conversion method is mainly used to convert a string. parseint returns Nan if the first character of the result is not a numeric character or a negative sign.
Parseint () can accept two parameters. The first value indicates the value to be converted, and the second parameter indicates the conversion method (in decimal, hexadecimal, or octal format ). If there is no second parameter, it is converted to decimal by default.
3. parsefloat () conversion method. This method always ignores the leading 0 and only one decimal point is valid. if there is only a number 0 after the decimal point, an integer is returned.
Ii. Other methods of Number Type
Tofixed () is automatically rounded to the nearest integer. A parameter is used to indicate the number of decimal places returned.
Toexponential () returns a string in exponential notation.
Toprecision (), automatically select the appropriate representation method.
Note: all three methods return strings.
Iii. Others
Isnan () can determine whether the given value is a numerical value. This function converts the passed value and determines whether it can convert digits.
Isfinite () can be used to test whether the value is within the data range supported by the browser.
The highest precision of floating point numbers is 17 decimal places. Do not test (0.1 + 0.2 = 0.3)