float f11 = 0;
f11 += 0.1F;//0.1
f11 += 0.2F;//0.3
f11 += 0.3F;//0.6
f11 += 0.4F;//1.0
float f2 = 0.4F + 0.3F + 0.2F + 0.1F;
float f22 = 0;
f22 += 0.4F;//0.4
f22 += 0.3F;//0.700000048
f22 += 0.2F;//0.900000036
f22 += 0.1F;//1.0
To add to astander's answer - this is how values looks for floats. Due to lower precision (7 digits for floats, 14-15 for doubles) values ends up being displayed differently and accidentally equal to what you expected.
But that's it - it's just coincidence! Never depend on it. Floating point operations are associative, nor precise. Never compare floats or doubled using ==
, always consider using some margin value. This sample works for 1
, but for other value it will surly fail.