Returns the remainder of dividing the first value by the second.
SDK
- Xcode 9.0+
Framework
- Swift Standard Library
Declaration
Parameters
lhsThe value to divide.
rhsThe value to divide
lhsby.rhsmust not be zero.
Discussion
The result of the remainder operator (%) has the same sign as lhs and has a magnitude less than rhs.
let x = 22 % 5
// x == 2
let y = 22 % -5
// y == 2
let z = -22 % -5
// z == -2
For any two integers a and b, their quotient q, and their remainder r, a == b * q + r.