How javascript converts word characters to floating-point types
This article mainly shows you "javascript how to convert word characters into floating-point types", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "javascript how to convert word characters into floating-point types" this article.
Javascript character conversion floating point type method: 1, the use of parseFloat () method, this method can parse a string and return a floating point number, syntax "parseFloat (character variable)"; 2, the use of "+" operator, syntax "+ (character variable)".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Javascript character types convert floating point types
Method 1. Use the parseFloat () method
The parseFloat () method takes a string and converts it to a floating-point number; it parses a string and returns a floating-point number.
If the string does not contain a numeric value, or if the first character of the string is not a number, NaN is returned, indicating that it is not a number.
Example:
Var n = "- 33.565"; var floatValue = parseFloat (n); console.log (floatValue)
Method 2: use the "+" operator
In javascript, you can use JavaScript's implicit type conversion feature to convert string values to float.
Implicit type conversions automatically convert types based on operators.
Example:
Var n = "33.565"; [xss_clean] ("the value before conversion is" + n + "and the type is" + typeof n + "
"); var floatValue = + (n); [xss_clean] (" the converted value is "+ n +" and the type is "+ typeof floatValue +"
")
The above is all the content of the article "how javascript converts word characters to floating point types". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!