A static object, Math, has many methods.
Let's experience the methods that control various properties of numbers through examples.
|
|
<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> Math Object </title> |
|
|
|
|
|
<script type="text/javascript"> |
|
|
//<!CDATA[ |
|
|
|
|
|
/* |
|
|
Because it's a static object, no instances are created. |
|
|
Methods: floor(num), ceil(num), round(num), max(num1, num2), min(num1, num2), 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 />"); |
|
|
// returns a number between 0 ~ 1 (changes every time you refresh) |
|
|
|
|
|
//]]1]]]]> |
|
|
</script> |
|
|
|
|
|
</head> |
|
|
|
|
|
|
|
|
<body> |
|
|
|
|
|
</body> |
|
|
|
|
|
</html> |
|
|
|
