Swift Double squareRoot()

In this tutorial, we will learn about the Swift Double squareRoot() method with the help of examples.

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


// 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:


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()



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?