Home  >  Article  >  Web Front-end  >  在JavaScript中使用开平方根的sqrt()方法_基础知识

在JavaScript中使用开平方根的sqrt()方法_基础知识

WBOY
WBOYOriginal
2016-05-16 15:54:512424browse

 这个方法返回一个数的平方根。如果数的值是负的,开方返回NaN。
语法

Math.sqrt( x ) ;

下面是参数的详细信息:

  •     x: 一个数字

返回值:

  • 返回一个数字的正弦值。

例子:

<html>
<head>
<title>JavaScript Math sqrt() Method</title>
</head>
<body>
<script type="text/javascript">

var value = Math.sqrt( 0.5 );
document.write("First Test Value : " + value ); 
 
var value = Math.sqrt( 81 );
document.write("<br />Second Test Value : " + value ); 

var value = Math.sqrt( 13 );
document.write("<br />Third Test Value : " + value ); 

var value = Math.sqrt( -4 );
document.write("<br />Fourth Test Value : " + value ); 
</script>
</body>
</html>

这将产生以下结果:

First Test Value : 0.7071067811865476
Second Test Value : 9
Third Test Value : 3.605551275463989
Fourth Test Value : NaN 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn