//JS代码
<!DOCTYPE html>
<html>
<head>
<title>Math对象</title>
</head>
<body>
<script type="text/javascript">
/*
Math.abs(x);//返回绝对值
Math.acos(x);//返回反余弦值
Math.ceil(x);//向上取值
Math.floor(x);//向下取值
Math.max(x,y);//返回最大值
Math.min(x,y);//返回最小值
Math.pow(x,y);//返回x的y次幂
Math.random();//返回0~1之间的随机数
Math.round(x);///四舍五入
Math.sqrt(x);//返回数的平方根
Math.toSource();//返回该对象的源代码
Math.valueOf()//返回Math对象的原始值
*/
//部分代码演示
document.write("abs "+Math.abs(-3)+"<br>");
document.write("ceil "+Math.ceil(4.1)+"<br>");
document.write("floor "+Math.floor(3.8)+"<br>");
document.write("max "+Math.max(-3,1)+"<br>");
document.write("min "+Math.min(-3,1)+"<br>");
document.write("pow "+Math.pow(-3,3)+"<br>");
document.write("sqrt "+Math.sqrt(4)+"<br>");
document.write("random "+Math.random()+"<br>");
</script>
</body>
</html>
JS Math对象
最新推荐文章于 2023-01-17 13:52:26 发布