js字符串和数字之间的转换
程序员文章站
2024-03-17 13:21:40
...
数字转字符串
var x = 1234567;
var s = x.toString();
var len = s.length;
console.log(x)
console.log(s)
console.log(len)
console.log(typeof(x), typeof(s))
输出:
1234567
1234567
7
number string
字符串转数字
var y = s + '890'
var n = parseInt(y)
console.log(y, typeof(y), n, typeof(n))
输出:
1234567890 string 1234567890 number