欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > JavaScript中的Math对象详解

JavaScript中的Math对象详解

2025/3/9 22:59:49 来源:https://blog.csdn.net/qq_36324341/article/details/142438287  浏览:    关键词:JavaScript中的Math对象详解

JS中的算术运算

基本运算:加减乘除求余数,+-*/%.

复杂运算:通过Math对象的属性定义的函数和常量来实现。

代码实现:

<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>3.1.3 JS中的算术运算</title></head><body><h1>JS中Math的复杂运算</h1><script>document.write("幂计算Math.pow(2,53),结果:"+Math.pow(2,53)+"<br>");document.write("四舍五入Math.round(5.8),结果:"+Math.round(5.8)+"<br>");document.write("向上求整Math.ceil(5.1),结果:"+Math.ceil(5.1)+"<br>");document.write("向下求整Math.floor(4.9),结果:"+Math.floor(4.9)+"<br>");document.write("绝对值Math.abs(-5),结果:"+Math.abs(-5)+"<br>");document.write("返回最大值Math.max(5,9,8),结果:"+ Math.max(5,9,8)+"<br>");document.write("返回最小值Math.min(3,6,9),结果:"+Math.min(3,6,9)+"<br>");document.write("大于等于0小于1的伪随机数Math.random(),结果:"+Math.random()+"<br>");document.write("圆周率Math.PI,结果:"+Math.PI+"<br>");document.write("自然对数Math.E,结果:"+Math.E+"<br>");document.write("平方根Math.sqrt(3),结果:"+Math.sqrt(3)+"<br>");document.write("立方根Math.pow(27,1/3),结果:"+Math.pow(27,1/3)+"<br>");document.write("三角函数Math.sin(Math.PI/2),结果:"+Math.sin(Math.PI/2)+"<br>");document.write("自然对数Math.log(10),结果:"+Math.log(10)+"<br>");document.write("以10为底的对数Math.log10(1000),结果:"+Math.log10(1000)+"<br>");document.write("以2为底的对数Math.log2(1024),结果:"+Math.log2(1024)+"<br>");document.write("自然指数Math.exp(5),结果:"+Math.exp(5)+"<br>");</script></body>
</html>

页面效果:

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词