本教程操作环境:windows7系统、javascript1.8.5版、dell g3电脑。
javascript将数字转为字符串
1、利用加号运算符
当数字与空字符串相加运算时,javascript 会自动把值转换为字符串。
var n = 123;n = n + ;console.log(typeof n); //返回类型为 string
2、使用tostring()方法
var n = 123;n = n.tostring();console.log(typeof n);
3、使用tofixed()方法
var n = 123.21;n = n.tofixed();console.log(typeof n);
【推荐学习:javascript高级教程】
以上就是javascript如何将数字转为字符串的详细内容。
