aschepler explained the mechanics of what is going well, but the main problem with your code is to use a value that does not exist as a float in the code, which depends on the value of its approximation in an unstable way. If you want to multiply by 0.9 (the actual number is 0.9 = 9/10, and not a floating point value of 0.9 or 0.9f ), you should multiply by 9, then divide by 10 or forget about floating point types and use decimal arithmetic library.
A cheap and dirty road around the problem, when unstable points are isolated, as in your example here, it is just to add a value (usually 0.5), which, as you know, will be more than an error, but less than the difference with the next integer before truncation.
source share