My current method of rounding to x decimal places:
public static float roundInc(float value, float increment) {
float inc = 1f / increment;
return Math.round(value * inc) / inc;
}
Which works fine for certain numbers, but seems to break, and I can't seem to figure this out.
I pass through the value 2.109375 Output of the function returns 2.11 Then I add that to 5.0 (is also a float, stored in a float array (float[])), and for some bizarre reason, adding the 2.11 + 5.0 returns 7.1099997...
Can someone explain this? Cause as far as I can see, after printing the two 2.11, and 5.0, showing those two exact values, then added together breaks everything...