<script> /** * Math对象 数学对象 * * 特点: * Math不用创建,直接使用 * * 方法: * random():产生一个0~1之间的随机数(包含0,不包含1) * ceil():向上取整 * floor():向下取整 * round():四舍五入 * * 属性: * PI:圆周率 * */ document.write(Math.PI+"<br>"); document.write(Math.round(4.63)+"<br>"); document.write(Math.ceil(5.1)+"<br>"); document.write(Math.floor(4.9)+"<br>"); //取1~100之间的随机整数 let number = Math.random()*100; document.write(Math.ceil(number)+"<br>"); </script>
效果: