rounding double in java
Rounding a double in java is very simple. If you have to round it to the nearest integer you could use the Math.round(double) method, but what about if you have to round it with a desired number of decimals?
Quite easy too. Using the BigDecimal.setScale(int,int) method you can choose how to round it. Following a quick example:
BigDecimal bd = new BigDecimal(123.45);
bd = bd.setScale(1,BigDecimal.ROUND_HALF_UP);
System.out.println(bd.doubleValue()); //should output 123.5


If value is 100.85 return 100.8 , but is 100.9 .. why?
BigDecimal bd = new BigDecimal(100.85);
bd = bd.setScale(1,BigDecimal.ROUND_HALF_UP);
System.out.println(bd.doubleValue());