Swift Int Division is special
Every print statement below yields 0.0
var c:Double = 0.0
let a:Int = 1
let b:Int = 5
print("a/b = \(Double(a/b * 100))")
c = Double(a/b * 100)
print("c = \(c)")
Written on March 24, 2018
Technical Solutions Engineer for Google Cloud Speech APIs
Every print statement below yields 0.0
var c:Double = 0.0
let a:Int = 1
let b:Int = 5
print("a/b = \(Double(a/b * 100))")
c = Double(a/b * 100)
print("c = \(c)")