Listing 4.20: Swift 3 - Using Remainder on a Double results in an error


When following the chapter, the line that states:

print(12.4 % 5.0)

I receive the error: ‘%’ is unavailable: Use truncatingRemainder instead.

This may be an error introduced in Swift 3. I am using Xcode 8 beta 5.

Just wondering how you would rectify this?


Taking a look at the documentation, you use dot-syntax at the end of the floating-point value, and then pass the denominator as the parameter:

12.4.truncatingRemainder(dividingBy: 5.0)


Thank you i appreciate the help.