@Test public void testRound() { double exact = 123.45678; double round = MathUtil.round(exact, 2); Assert.assertEquals(round, 123.46, "Rounding " + exact + " to 2 decimals."); }
public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); BigDecimal rounded = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return rounded.doubleValue(); }
MathUtil { public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); BigDecimal rounded = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return rounded.doubleValue(); } }
MathUtil { public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); BigDecimal rounded = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return rounded.doubleValue(); } private  MathUtil(); }
MathUtil { public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); BigDecimal rounded = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return rounded.doubleValue(); } private  MathUtil(); static double round(double value, int decimalPlaces); }
MathUtil { public static double round(double value, int decimalPlaces) { BigDecimal bd = new BigDecimal(value); BigDecimal rounded = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP); return rounded.doubleValue(); } private  MathUtil(); static double round(double value, int decimalPlaces);  }