Code example for BigDecimal

Methods: floatValuesetScale

0
     
    private float roundFloat(float f){
        String tmp = String.valueOf(gridGap);
        int ind = tmp.indexOf(".");
        int m = tmp.length() - ind;
        BigDecimal   bd = new BigDecimal(f);
        bd = bd.setScale(m, BigDecimal.ROUND_HALF_UP);
        return bd.floatValue();
    } 
     
     
} 
Connect your IDE to all the code out there  Get Codota for Java