I'm migrating our codebase to Swift 3 and I've come across a compilation issue that I can't explain or fix.
I have a method in a Double
extension that rounds the Double
to a certain number of digits:
public func roundToPlaces(places: Int) -> Double {
let divisor = pow(10.0, Double(places))
return round(self * divisor) / divisor
}
For example:
12.34567.roundToPlaces(2)
should return 12.35
. However, I'm getting a compilation issue for the round
method used in this extension. It's saying that I Cannot use mutating member on immutable value: 'self' is immutable
.
Any ideas on what's going on here? How do I fix this issue?