I am currently attempting:
if (4.750 % 0.125 == 0 )
but it looks like c# doesn't want decimal for mod operation. How do I check if a number is a multiple of 0.125 then?
thanks!
I am currently attempting:
if (4.750 % 0.125 == 0 )
but it looks like c# doesn't want decimal for mod operation. How do I check if a number is a multiple of 0.125 then?
thanks!
 
    
    Comparing floats/doubles with zero is pretty dangerous, because of the floating-point precision. You can do two things:
or
if (Math.Abs(a % b) < 0.001)
 
    
    What you could do is create a custom function to find the mod of any decimals for you:
static double DecimalMod(double a, double b) {
        if (a < b) {
            return a;
        }
        return DecimalMod(a - b, b);
}
And since comparing doubles will be annoying with floating-point precision, you'll want to use the bounds checking of:
if (Mathf.Abs(DecimalMod(4.750, 0.125)) < 0.01) {
     // Do Stuff
}```
