Home>

We become indebted to.

In Swift, timer and operator% are used to create a mechanism that operates when the remainder becomes 0.

It feels like it works once every second.

At first, it was implemented with an integer Int, and in that case, the remainder became 0, so there was no problem in operation, but

When I tried to implement it using floating point numbers in more detail,

Since% cannot be used in Int in swift
truncatingRemainder (dividingBy: num)
I decided to use.

However, is this method wrong in calculation or is it such a specification?
The remainder does not become 0.

// Playground
import UIKit
var num: Float = 1.2
var num2: Float = 6.0
let result = num2.truncatingRemainder (dividingBy: num)
print (result)


How can the remainder be cleanly reduced to 0?

Or if I want to implement a mechanism of floating point number once every ~ second, please tell me what is the correct answer.

I would appreciate it if you could answer.