Swift Double squareRoot()

The squareRoot() method returns the square root of the given value.

Example

// return the square root of 4 var result = 4.squareRoot()
print(result) // Output: 2.0

squareRoot() Syntax

The syntax of the double squareRoot() method is:

num.squareRoot()

Here, num is the number whose square root is to be calculated.


squareRoot() Parameters

The squareRoot() method doesn't take any parameter.


squareRoot() Return Values

  • returns the square root of the num.

Example: Swift Double squareRoot()

// square root of 9
var result1 = 9.squareRoot()
print(result1) // square root of 54.7
var result2 = 54.7.squareRoot()
print(result2) // square root of 0
var result3 = 0.squareRoot()
print(result3)

Output

3.0
7.395944834840239
0.0

In the above example, we have used the squareRoot() method to find the square root of the given numbers.

Did you find this article helpful?