If you feel you must continue with your approach, and you really want to try to use modulus on a type double, then you could write your own function to mimic the modulus operator for ints.
take 2 variables x and y;
if x < y what is the remainder if you remove as many x's from y as you can.OR in pseudocode, maybe somehting like this:
x, y, remainder remainder = y while x less than or equal to remainder remainder = remainder - x
Is there an easier approach that I'm not seeing?