피드로 돌아가기
새로워지기·서른의 생활코딩

샘플소스3) javascript 기본 문서구조 ( 숫자 객체 )

NS
normalstory
표지 이미지

정적객체인 Math는 다양한 메소드를 가지고 있다.
숫자가 가진 다양한 속성을 컨트롤하는 메소드들을 예제를 통해 경험해보자.





<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko" lang="ko">




<head>


<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />




<title> 수학 객체 </title>




<script type="text/javascript">


//<!CDATA[




/*


정적 객체이기 때문에 인스턴스는 만들지 않는다.


메소드: floor(숫자),ceil(숫자),round(숫자),max(숫자1,숫자2),min(숫자1,숫자2),random()


*/




var num1,num2;


num1=15.2;


num2=15.7




document.write(Math.round(num1)+"<br />");


document.write(Math.floor(num1)+"<br />");


document.write(Math.ceil(num1)+"<br />");


document.write(Math.round(num2)+"<br />");


document.write(Math.floor(num2)+"<br />");


document.write(Math.ceil(num2)+"<br />");




document.write(Math.random()+"<br />");


// 0 ~ 1 사이에서 난 수로 나옮(새로고침때마다 바뀐다)




//]]1]]]]>


</script>




</head>






<body>




</body>




</html>



친절한 찰쓰씨
글쓴이
친절한 찰쓰씨
친절한 찰쓰씨 · 일상 UX 디자이너
기획·디자인·단상을 조용히 기록합니다.
작가 페이지에서 더 보기

이어서 읽기

새로워지기

꾸준히, 오래, 지치지 않고

Mar 31, 2026·8
새로워지기

테크 라이프 발란스

Feb 7, 2026·3
새로워지기

휴탈리티 박정렬

Feb 7, 2026·11