JS的数据类型转换
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
var num1 ="3.14"
var ret1 = parseFloat(num1) // #将字符串转换为数字
console.log(ret1,typeof ret1) // 3.14 'number'
var num2 ="100件"
var ret2 = parseInt(num2)
console.log(ret2,typeof ret2) // 100 'number' #将字符串转换为数字
var num3 ="第100件"
var ret3 = parseInt(num3)
console.log(ret3,typeof ret3) // NaN 'number' #将字符串转换为数字
var num4 = 3.14
var ret4 = num4.toString() // 3.14 strings #将数字转换为字符串
console.log(ret4,typeof ret4)
</script>
</head>
<body>
<h1>welcome to JS!</h1>
</body>
</html>
标签:类型转换,console,log,3.14,number,JS,typeof,var,数据 来源: https://www.cnblogs.com/A121/p/16335550.html