본문 바로가기

IT Study/Web

[JavaScript] Math 관련 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
 
<p id="demo"></p>
 
<button onclick="myfunc()">버트은</button>
 
 
<script type="text/javascript">
 
function myfunc() {
    
    document.getElementById("demo").innerHTML
    //    = Math.round(4.5);    //반올림
    //    = Math.round(Math.random() * 10);    //반올림 해줘서 0~10 값이 나옴
    //    = Math.min( 1, 4, 5 ,8 ,9 ,2 );    //최솟값
    //    = Math.max( 1, 4, 5, 8 ,9 ,2 ); //최댓값
    //    = Math.ceil(4.1);    //올림
    //    = Math.floor(4.9); //내림
    //    = Math.E    //Euler
    //    = Math.PI     //PI값    
        = Math.SQRT2; //루트값
}
 
 
</script>
 
 
 
</body>
</html>
cs