First off this is the code I use :
public static float roundAt(float value , int digits) {
double pow = Math.pow(10, digits);
double retvalue;
retvalue = (value * pow);
retvalue = Math.round(retvalue);
retvalue = retvalue / pow;
return (float) retvalue;
}
So using this method I do the following
if I round these values:
roundAt(0.495f,2) = 0.5
roundAt(1.495f,2) = 1.5
roundAt(2.495f,2) = 2.49
I try to understand the logic behind this but I can't. I want the rounding to act the same everytime so I would get 2.5 with roundAt(2.495f,2)
. Any idea what's going on ?
Thank you