How does javascript convert strings into numbers and javascript strings?
How to convert a string to a number in javascript:
It may be used to convert a string to a number, especially in an environment involving digital computing. The following describes how to convert a string.
1). Convert the parseInt () function:
This function can parse a string and return an integer.
The code example is as follows:
ParseInt ("12px"); // returns 12 parseInt ("0xA"); // returns 10 parseInt ("2.3"); // returns 2 parseInt ("blue "); // return NaN
For more information, see section 1 of the parseInt () function in JavaScript.
2). Convert the parseFloat () function:
The conversion method of this function is similar to that of the parseInt () function, except that it can return a decimal floating point number, and the parseFloat () function does not have a base mode.
The code example is as follows:
ParseFloat ("12px"); // returns 12 parseFloat ("0xA"); // returns 0 parseFloat ("2.3"); // returns 2.3 parseFloat ("blue "); // return NaN
For more information, see section 1 of parseFloat () method in JavaScript.
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 8239.
For more information, see: http://www.softwhy.com/javascript/