I am implementing a business rule that says "a number must be in increments of 0.005 to be valid"
These are good:
123.005
123.0
These are bad:
123.004
123.1001
I've tried the modulus operator, but get unexpected numbers:
var x = 5.005;
var z = x % .005;
The result is 0.004999999999999789
Note: This question is NOT about rounding, it is about finding values that are increments of 0.05
Here's the solution:
//Multiply by 200 to get a full int value (.005 * 200 == 1)
if ((limitPrice * 200) % 1 !== 0) {
isFailure = true;
errorMsg = "Blah blah";
}