Wonderful world of floating point numbers:
printf("%.18f\n", 40.7*100); //prints 4070.000000000000454747 printf("%.18f\n", 20.7*100); //prints 2070.000000000000000000
In short: floating point numbers cannot accurately represent all rational numbers. In particular, neither 407/10 nor 207/10 can be represented accurately, and therefore the result of an integer conversion always has uncertainty about one unit.
The only rational numbers that can be represented exactly as binary floating point numbers are in the form of a "small odd integer force of the difference of two", or, in other words, those that have a small binary decomposition.
source share