Floating points are imprecise. 9.99999997e-07 is the closest number that can be represented as a float. Using a double would give much more precision... often enough for computation like that.
You should also write your expression in a way to avoid as much imprecision as possible. As floating point can represent exactly multiple of 1 up to about 15 digits but cannot represent exactly fractionnal number (except for fraction like 0.25, 0.5, 0.75 and other where the numerator would be an integer and the denominator a power of 2), it might be preferable to keep each value serate and do the final computation:
long long phase = (digit * temp * 1000 * 1000) / (ticks * 1000000.0);
It should be noted that
tick
should be a
double
too for improved precision. Otherwise, you loose all your precision there.
Finally, in some cases, you might also want to round the resulting number. This is particulary the case where converting back to integer. If the result of phase computation is something like 199999.998, you probably want a result of 200000. Without rounding, the value would be truncated to 199999.
long long phase = floor((digit * temp * 1000 * 1000) / (ticks * 1000000.0) + 0.5);
When you do computation like that, it is useful to know the language specification and learn how floating points works. Ideally, this is the kind of things, one would learn in scholl but if you are Learning by yourself, you should be able to find a lot of information on Google.