JavaScript数值类型转换

Js入门与实战 admin 481浏览
	
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>document</title>
</head>
<body>
<script type="text/javascript">
var a = '1';
var b = Number(a);
console.log(typeof b);
var c = Number('c');
var d = Number(null);
var e = Number(undefined);
console.log(c,d,e);
var f = parseInt('2');
var g = parseInt('k23');
var h = parseInt(null);
var i = parseInt(undefined);
console.log(f,g,h,i);
var j = parseFloat('1.23def');
var k = parseFloat('1.3.4.5');
var l = parseFloat('h34');
var m = parseFloat(null);
var n = parseFloat(undefined);
console.log(j,k,l,m,n)
</script>
</body>
</html>

转载请注明:大灰牛博客 » JavaScript数值类型转换