数学计算示例
2025年4月30日小于 1 分钟
示例代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数学内置对象</title>
</head>
<body>
<script type="text/javascript">
//浮点数四舍五入 获取整数
var a=Math.round(3.14);
document.write(a+"<br/>");
//获取最大值
var b=Math.max(10,20,30);
document.write(b+"<br/>");
//获取最小值
var c=Math.min(10,20,30);
document.write(c+"<br/>");
//向上取整
var d=Math.ceil(3.1111111);
document.write(d+"<br/>");
//向下取整
var e=Math.floor(2.9999999);
document.write(e+"<br/>");
//绝对值
var f=Math.abs(-10);
document.write(f+"<br/>");
//获取n次幂
var g=Math.pow(3,3);
document.write(g+"<br/>");
//求平方根
var h=Math.sqrt(9);
document.write(h+"<br/>");
//获取0-1之间的随机数
var j=Math.random();
document.write(j+"<br/>");
//获取任意数值间的随机数
function rand(m,n)
{
return Math.ceil(Math.random()*(n-m+1))+(m-1);
}
document.write(rand(30,100)+"<br/>");
</script>
</body>
</html>