The problem is a practical one, that there's no widespread agreement about what the % operator should do. It calculates a remainer, or a modulus, and it produces a positive result, or a negative result, or a result with the same sign as … whatever, it rounds, it truncates, towards the origin, towards positive infinity, towards negative infinity.
For those reasons, the designers of Swift decided to disallow the use of operator % with floating point numbers. Instead, you use one of the "remainder" functions:
to say what you mean.
this might help:
var nNum3:Float = 7.0 var nNum4:Float = 4.0 var nREnt = nNum3.truncatingRemainder(dividingBy: nNum4) print("Float - Reaminder after division:\(nREnt), type: \(type(of:nREnt))") let nNum1:Int = 7 let nNum2:Int = 4 let nRest = 7 % 4 print("Int - Reaminder after division:\(nRest), type: \(type(of:nRest))")
Float - Reaminder after division:3.0, type: Float
Int - Reaminder after division:3, type: Int
Solved. Working Fine...
var nNum3:Float = 5.2
var nNum4:Float = 1.0
var nREnt : Int = Int(nNum3.divided(by: nNum4))
var nRes1 : Float = nNum3.remainder(dividingBy: nNum4)
Remainder Operator % is used only for values of type Int
If you write
var nRes1 : Int = nNum3 % nNum4
then there will be no error