Trying to do server side validation (PHP), where there is the HTM5 number input:
<input ... min="1" max="20" step="0.1" />
The browser will allow you to enter a value such as "10.5", but how should this be double checked in PHP? for those browsers which won't do the validation (and the fact you shouldn't trust data from the browser).
if (fmod(floatval($value), 0.1) == 0) {
// valid
}
This does not work, as fmod() in this case returns "0.099999...", as per:
Why different results of 0.5 mod 0.1 in different programming languages?
You could multiply the $value by 10, and use the modulus check of 1 (rather than 0.1), so your doing integer maths... but what happens if the step was 0.01, or 0.003?