Your problem is that floats are represented internally using IEEE-754 . That is, in base 2, and not in base 10. 0.25 will have an accurate representation, but 0.1 does not and does not have 120.99 .
What really happens is that because of the floating point inactivity, the float ieee-754, closest to the decimal value of 120.99 , multiplied by 100 , is slightly lower than 12099 , so it is truncated to 12098 . The compiler should have warned you that you have a truncation from float to (my did).
The only reliable way to get what you expect is to add 0.5 to the float before truncating to int:
i = (f * 100) + 0.5
But beware floating point is inherently inaccurate when processing decimal values.
Edit:
Of course, for negative numbers it should be i = (f * 100) - 0.5 ...
source share