I am using following code to round down the decimal number
private float roundOffTwoDigits(float number) {
DecimalFormat toTheFormat = new DecimalFormat("0.0");
toTheFormat.setRoundingMode(RoundingMode.DOWN);
number = Float.valueOf(toTheFormat.format(number));
return number;
}
Now there are the output I am getting
Input Output
2.2 > 2.2
2.21 > 2.2
2.28 > 2.2
2.4 > 2.4
2.6 > 2.5(Why 2.5 it should be 2.6)
2.8 > 2.7(Why 2.7 it should be 2.8)
So even number after decimal place and if it is more than 5 it is decreasing the value which should not happen.
Somebody marked my quesion duplicate with this question here Is floating point math broken?, I am not sure why ?
That question is not at all related to java and android and not having answers and discussion I was expecting.