In a loop I am adding 0.10 till I reach the desired #, and getting the index. This is my code :
private static int getIndexOfUnits(float units) { int
Exact representation is not available with Float datatype.
BigDecimal will help you.Below example might be helpful for you
BigDecimal decimal=new BigDecimal(10.0); for (int i = 0; i < 10; i++) { decimal=decimal.add(new BigDecimal(.1)); System.out.println(decimal.floatValue()); }