How JavaScript converts a string to a number:
It is possible to convert a string into a number in the encoding, especially in the context of a digital computation, here's a quick introduction to how to convert.
1). parseint () function to convert:
This function can parse a string and return an integer.
The code example is as follows:
parseint ("12px"); // parseint ("0xA"); // returnto parseint ("2.3"); // returns 2parseint ("Blue"); // return nan
More on this, you can refer to the parseint () function section of JavaScript for more details.
2). Parsefloat () function to convert:
This function is converted in the same way as the parseint () function, except that it can return a decimal floating-point number, while the parsefloat () function does not have a base pattern.
The code example is as follows:
Parsefloat ("12px"); // parsefloat ("0xA"); // returns 0parsefloat ("2.3"); // return to 2.3parsefloat ("Blue"); // return nan
Refer to the parsefloat () method section of JavaScript for details.
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8239
For more information, refer to: http://www.softwhy.com/javascript/
How JavaScript converts a string to a number