In the previous chapter we know that in JavaScript code, when you add a character to a numeric value, the value is converted to a character, which means that the value entered by the user is converted to a character.
Now we're going to do such an example, and I want to add 1 and 2:
Obviously the result is not what we want, now we change the code to look like this:
The result is what we want, 1+2=3.
This means that we can convert the character type to a numeric type parseint ().
If there are numeric values and strings in the input value, can we get the values we want?
Look at the following code:
It is possible to obtain a value, but the result is 2 is not 2.34, this is because the parseint () function It resolves to is not a valid value will stop parsing when parsing to. (dot) stopped parsing, then how can we get to 2.34, see the following code:
By code we know that using the parsefloat () function resolves to a floating-point number, which is the value we want to get,
Next look at a special case, if the input string does not have a valid value, then the use of these two functions will get what, see the following code:
The Nan value is a special value in JavaScript, indicating that it is not a value.
Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/40892573 Emotional Control _
JavaScript Language Basics 6