The isEqual() method checks if one number is equal to another or not.
Example
isEqual() Syntax
The syntax of the isEqual() method is:
num.isEqual(to: otherNumber)
Here, num is a number.
isEqual() Parameters
The isEqual() method takes one parameter
otherNumber- the value to test
isEqual() Return Values
The isEqual() method returns boolean value
true- ifnumis equal tootherNumberfalse- ifnumis not equal tootherNumber
Example 1: Swift Double isEqual()
Output
false true
Here, since 4 is not equal to 2, the isEqual() method returns false. However, 2.0 is equal to 2, the method returns true.
Example 2: Using if…else With isEqual()
Output
The condition is false
Here, since 88 is not equal to 88.2, the condition is false so the code inside the else block is executed.