How to convert a number into a string in javascript
This article introduces how to convert numbers into strings in javascript. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.
1. Use the plus sign "+" operator and the syntax "number +".
Var n = 123 typeof n = n + "; console.log (typeof n); / / return type is string
2. Use toString () method, syntax "numeric variable .toString ()".
Var a = 1.000 console.log var b = 0.0001 console.log var c = 1e Mui 1x console.log (b.toString ()); / / returns the string "1" (c.toString ()); / / returns the string "0.0001" (c.toString ()); / / returns the string "0.0001"
3. Convert a number to a decimal format string with toFixed (), toExponential (), or toPrecision ().
Var a = 10 position console.log (a.toFixed (2)); / / return the string "10.00" console.log (a.toFixed (4)); / / return the string "10.0000" about how to convert numbers into strings in javascript and that's it. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.