Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Double isEqual()
In this tutorial, we will learn about the Swift Double isEqual() method with the help of examples.
The isEqual() method checks if one number is equal to another or not.
Example
// check if 10 is equal to 10 or not
var result = 10.isEqual(to: 10)
print(result)
// Output: true
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()
// check if 4 is equal to 2 or not
var result1 = 4.isEqual(to: 2)
print(result1)
// check if 2.0 is equal to 2 or not
var result2 = 2.0.isEqual(to: 2)
print(result2)
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()
// check if 88 is equal to 88.2 or not
if 88.isEqual(to: 88.2) {
print("The condition is true")
}
else {
print("The condition is false")
}
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.
Did you find this article helpful?