Swift Modulus Division
To perform modulus division of two numbers in Swift, we can use Swift Modulus Division Arithmetic Operator.
Modulus Division Operator
% takes two integers as operands and returns the reminder value when the first operand is divided by the second operand.
Modulus Division Operator cannot be applied for Float/Double values.
The syntax to find the modulus division of two numbers is
a % b
b are operands. These operands should be of type Int.
1. Modular Division with integer values
In the following program, we will perform modulus division of two integers.
var a = 11 var b = 4 var result = a % b print("The result is \(result)")
2. Modular Division with Double values
Now, let us try to find the modulus division of two Double values. We know that we cannot perform modulus division on Double or Float values.
In this Swift Tutorial, we learned how to perform Modulus Division in Swift programming using Modulus Operator. We have seen the syntax and usage of Modulus Operator with examples.