I have spent almost all day trying to figure out why this is happening, I had code that incremented a float if it was not a whole number until it was a whole number, i'd trigger it by incrementing the value by 0.01 and the loop keeps incrementing it by 0.01 until it is an integer however it never stops, debugging it I noticed that the number to becoming increasingly inaccurate as the loop progressed leading to it being 0.0000066 out by the end.
I thought maybe the variable might had been being accessed elsewhere somehow so I created it simply in an empty "main" program:
float value = 0;
for (int i=0; i<100; i++) {
value += 0.01f;
}
System.out.println(value); // Displays 0.99999934
System.out.println(value == 1); // Just in case it's displaying wrong in println (displays false)
Why is this not 1 by the end? I don't think it could be anything to do with data types as i'm adding a float to a float.