수학 계산을 위한 내장 객체이다.

내장 객체이기 때문에 Date처럼 new 연산자로 객체를 생성하지 않는다.

 

 

<script>
	
	document.write("PI = "+Math.PI+"<br>");
	document.write("오일러 상수 = "+Math.E+"<br>");
	document.write("절대값 = "+Math.abs(-30)+"<br>");
	document.write("최대값 = "+Math.max(10,5,3,34,5,6,7,8,35,432445)+"<br>");
	document.write("최소값 = "+Math.min(2132,345,322,3,33,1,6,7)+"<br>");

	var num = 2.5234;
	document.write("<br>"+"var num = "+num+"<br>");
	document.write("올림 = "+Math.ceil(num)+"<br>");
	document.write("반올림 = "+Math.round(num)+"<br>");
	document.write("내림 = "+Math.floor(num)+"<br>");
	document.write("난수 = "+Math.random()*10+"<br>");
	document.write("거듭제곱 = "+Math.pow(num, 3)+"<br>");
	document.write("제곱근 = "+Math.sqrt(num)+"<br>");
</script>

 

 

 

 

 

Math.random()

0~1 사이의 난수가 발생한다.

보통 ceil함수에 중첩하여 10을 곱해서 사용한다.

 

<script>
	Math.ceil(Math.random()*10)
</script>

 

 

'웹표준 > 자바스크립트' 카테고리의 다른 글

이벤트 처리 방법  (0) 2022.08.16
이벤트와 이벤트 핸들러  (0) 2022.08.16
String 객체  (0) 2022.08.12
배열과 Array 객체  (0) 2022.08.12
Date 객체와 날짜와 시간  (0) 2022.08.12

+ Recent posts