我们来看一下sqrt函数的基本语法
math.sqrt(value)
平方根数需要计算。
返回作为参数传递的数字的平方根。
需要注意的是:
1、作为参数传递的非数字字符串返回nan
2、作为参数传递的多于1个整数的数组返回nan
3、作为参数传递的负数返回nan
4、作为参数传递的空字符串返回nan
5、作为参数传递的空数组返回nan
我们来看具体的示例
代码如下
<!doctype html><html><head> <meta charset="utf-8"> <title></title></head><body><script type="text/javascript"> document.write(math.sqrt(2)+"<br>"); document.write(math.sqrt(2.56)+"<br>"); document.write(math.sqrt(-2)+"<br>"); document.write(math.floor("javascript")+"<br>"); document.write(math.floor(7.2+9.3)); </script> </body></html>
执行结果如下
1.41421356237309511.6nannan16
本篇文章到这里就全部结束了,更多精彩内容大家可以关注的其他相关栏目教程!!!
以上就是sqrt函数怎么使用的详细内容。