Q:

How to check if a float is a multiple of another float in Swift

I receive a float number from the user and check if it's valid depending on an increment defined (0.1, 0.5, 0.01, etc). For example, if the increment is 0.5, then 1.0, 1.5, 2.0 are valid but 1.2 is not. I'm using modulo to check if it is valid.
if (input % increment) == 0 {
    println("Pass")
} else {
    println("Fail")
}

The problem is that when the increment is 0.1, most of the valid values of input are detected as invalid.
I used the formula given in this answer and it improves the detection of valid inputs but still fails most of the time.

A:

Your problem is that 0.1 isn't exactly representable in binary whereas 0.5 for instance is. this means that 0.1 * 5 doesn't equal 0.5. It's a lot like in decimal where (1 / 3) * 3 ≃ 0.3333333 * 3 = 0.99999999 not 1. To solve this sort of problem you can introduce an epsilon. An epsilon is a very small value, and you check whether your result is only a very small distance from the value you actually want, if it is you hope that the value is correct.

A:

To handle numbers with one number after the decimal point you could do:
if (input * 10) % (increment * 10) == 0 {
    println("Pass")
} else {
    println("Fail")
}

To handle numbers with more than one number after the decimal point just increase the multiple. For example, if (input * 100000) % (increment * 100000) == 0.

A:

Based on James Snook's answer, I ended up with this solution.
let epsilon = 1e-6
let division = input / increment
let diff = abs(division - round(division))
if (diff < epsilon) {
    println("Pass")
} else {
    println("Fail")
}

