web前端全系列 教程
1839个小节阅读:2243.5k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
Math.round
方法用于四舍五入
xxxxxxxxxx
Math.round(0.1) // 0
Math.round(0.5) // 1
Math.round(0.6) // 1
温馨提示
它对负数的处理(主要是对
0.5
的处理)
xxxxxxxxxx
Math.round(-1.1) // -1
Math.round(-1.5) // -1
Math.round(-1.6) // -2
Math.pow
方法返回以第一个参数为底数、第二个参数为幂的指数值
xxxxxxxxxx
// 等同于 2 ** 2
Math.pow(2, 2) // 4
// 等同于 2 ** 3
Math.pow(2, 3) // 8
下面是计算圆面积的方法
xxxxxxxxxx
var radius = 20;
var area = Math.PI * Math.pow(radius, 2);
Math.sqrt
方法返回参数值的平方根。如果参数是一个负值,则返回NaN
xxxxxxxxxx
Math.sqrt(4) // 2
Math.sqrt(-4) // NaN
Math.log
方法返回以e
为底的自然对数值
xxxxxxxxxx
Math.log(Math.E) // 1
Math.log(10) // 2.302585092994046
Math.exp
方法返回常数e
的参数次方
xxxxxxxxxx
Math.exp(1) // 2.718281828459045
Math.exp(3) // 20.085536923187668
实时效果反馈
1. 下列代码计算圆的面积,横线处应该填写的内容是:
xxxxxxxxxx
var radius = 20;
var area = ___ * ___(radius, 2);
A Math.PI
Math.pow
B Math.pow
Math.PI
C Math.pow
Math.sqrt()
D Math.PI
Math.sqrt()
2. 下列那个代码是平方根的数学函数:
A Math.PI
B Math.pow
C Math.sqrt()
D Math.log
答案
1=>A 2=>C