Home > Web Front-end > JS Tutorial > body text

How to use sqrt function

不言
Release: 2022-01-12 15:47:01
Original
108708 people have browsed it

The sqrt function in How to use sqrt function is used to return the square root of a number, which is the square root. In the following article, we will take a closer look at how to use the sqrt function.

How to use sqrt function

Let’s take a look at the basic syntax of the sqrt function

Math.sqrt(value)
Copy after login

The square root number needs to be calculated.

Returns the square root of the number passed as argument.

It should be noted that:

1. A non-numeric string passed as a parameter returns NaN

2. An array of more than 1 integer passed as a parameter returns NaN

3. Negative numbers passed as parameters return NaN

4. Empty strings passed as parameters return NaN

5. Empty arrays passed as parameters return NaN

Let’s look at the specific examples

The code is as follows

<!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("How to use sqrt function")+"<br>");     
      document.write(Math.floor(7.2+9.3));           
</script> 
</body>
</html>
Copy after login

The execution results are as follows

1.4142135623730951
1.6
NaN
NaN
16
Copy after login

This article ends here, more exciting content for you You can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use sqrt function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template