Round Off In N Decimal Places Using Java
|
|
This simple method will round off a value in N decimal places.
1 2 3 4 5 | public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } |









