js格式转换
作者:互联网
//字符串转布尔 var a = 'true' //console.log(a, typeof a) var a1 = Boolean(a) //console.log(a1, typeof a1) //布尔转字符串 var b = true //console.log(b, typeof b) //var b1 = b.toString() var b1 = String(b) //console.log(b1, typeof b1) //转为数字 var c = '2.23, 2.3' //parseFloat(): parseFloat()把字符串转换成浮点数,parseFloat()和parseInt非常相似, //不同之处在于parseFloat会解析第一个. 遇到第二个.或者非数字结束如果解析的内容里只有整数,解析成整数 console.log(c, typeof c) //var c1 = parseInt(c) //var c1 = parseFloat(c) var c1 = Number(c) console.log(c1, typeof c1)
标签:console,log,js,parseFloat,typeof,var,格式,c1,转换 来源: https://www.cnblogs.com/fxw1/p/14677040.html