Javascript method to convert numbers to strings: 1. Add numbers to empty strings, syntax "num """; 2. Use toString() method, syntax "num.toString() "; 3. Use toFixed() method, syntax "num.toFixed()".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
javascript converts numbers into strings
1. Use the plus operator
When a number is added to an empty string, JavaScript automatically converts the value to a string.
var n = 123; n = n + ""; console.log(typeof n); //返回类型为 string
2. Use toString() method
var n = 123; n = n.toString(); console.log(typeof n);
3. Use toFixed() method
var n = 123.21; n = n.toFixed(); console.log(typeof n);
[Recommended learning: javascript advanced tutorial】
The above is the detailed content of How to convert numbers to string in javascript. For more information, please follow other related articles on the PHP Chinese website!