<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=">
<script type="text/javascript">
var a, b;

a = "123";
b = Number(a);
console.log(b); // 123
console.log( b === 123); // true

a = "123.57";
b = Number(a); // 123.57
console.log(a + " : " + b); //123.57 : 123.57

a = "1,234";
b = Number(a); // NaN
console.log(a + " : " + b); // 1,234 : NaN

a = "123a";
b = Number(a); // NaN
console.log(a + " : " + b); // 123a : NaN

a = "";
b = Number(a); // 0
console.log(a + " : " + b); //  : 0

a = null;
b = Number(a); // 0
console.log(a + " : " + b); // null : 0

a = "kor";
b = Number(a); // NaN
console.log(a + " : " + b); // kor : NaN

a = "0x11";
b = Number(a); // 17
console.log(a + " : " + b); // 0x11 : 17

</script>


</head>
<body>

<h3>숫자로 변환 - Number() 함수</h3>

</body>
</html>

+ Recent posts