IT story/JSP

[JSP 강의] L15JavaScript (L03Number.html)

jason719 2016. 11. 17. 15:38

2016. 11. 17. (Thu)

L15JavaScript

L03Number
Number 데이터 타입에 대해 알아보자

ex) L03Number.html

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Number Functions</title>

</head>

<body>

<h1>Number 데이터 타입을 다루자</h1>

<hr/>

<script>

var x = true;

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>Number(x) : "+Number(x)+"</h3>");

x =false;

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>Number(x) : "+Number(x)+"</h3>");

x = "100"; //Integer.parseInt("100"); -> Number("100");

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>typeof Number(x) : "+typeof Number(x)+"</h3>");

x = "10 20"; //Integer.parseInt("100"); -> Number("100");

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>Number(x) : "+Number(x)+"</h3>");

//NaN -> Not-a-Number 넘버 포맷의 오류가 발생되면 대입되는 값.

document.write("<hr/>");

x = "10.3333";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseInt(x) : "+parseInt(x)+"</h3><p>->정수로 반환</p>");

x = "10 20";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseInt(x) : "+parseInt(x)+"</h3>");

x = "10 aa";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseInt(x) : "+parseInt(x)+"</h3>");

x = "aa 10";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseFloat(x) : "+parseFloat(x)+"</h3>");

document.write("<hr/>");

x = "10.3333";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseFloat(x) : "+parseFloat(x)+"</h3><p>->실수로 반환</p>");

x = "10.3333 20";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseFloat(x) : "+parseFloat(x)+"</h3>");

x = "10.3333 aa";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseFloat(x) : "+parseFloat(x)+"</h3>");

x = "aa 10.3333";

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>parseFloat(x) : "+parseFloat(x)+"</h3>");

x = 9.656;

document.write("<h3>x : "+x+"</h3>");

document.write("<h3>x.toFixed(0) : "+x.toFixed(0)+"</h3>");

document.write("<h3>x.toFixed(1) : "+x.toFixed(1)+"</h3>");

document.write("<h3>x.toFixed(2) : "+x.toFixed(2)+"</h3>");//미화($)에서 많이 사용됨

document.write("<h3>x.toFixed(3) : "+x.toFixed(3)+"</h3>");

document.write("<h3>x.toFixed(4) : "+x.toFixed(4)+"</h3>");

document.write("<hr/>");

document.write("<h3>Number.MAX_VALUE : "+Number.MAX_VALUE+"</h3>");


</script>

</body>

</html>

※ 출력내용