There is not really a mechanism to describe. Floats are only so precise, and so performing mathematical operations with them will result in some imprecision in results. I'll keep this discussion to Python, since it has different data types than C-based languages. It is important to remember that floats are approximations of fractions, and that these approximations are rarely 100% accurate to their fractional counterpart; the computer uses base-2, while we use base-10, and most fractions do not convert smoothly between the two. This becomes even more of an issue when mathematical operations are applied to fractions, especially to more than one of them. Python will provide an approximation of the values that the computer has stored/computed when displaying a float value. Even if it looks to be a perfectly precise decimal value, it is important to remember that such is not always, if ever, the case.
I recommend reading up on the Python documentation on this topic, as the same issue will apply no matter what language you are working with (thought different languages have different methods of dealing with it). Ultimately, the solution is not "how can I prevent this from happening," but "how can I ensure I get a value to my desired precision?" It sounds like you possibly solved this in your C version by turning the values into ints, which do not have this issue as those can be converted between base-2 and base-10 by the computer with ease.
Hope this helps clear things up for you. :) If it does, feel free to accept the answer with the check. But, if not, feel free to leave me a comment and I'll do my best to provide some more help.