/** * Obtains an instance that rounds to the specified number of decimal places. * <p> * This returns a convention that rounds to the specified number of decimal places. * Rounding follows the normal {@link RoundingMode#HALF_UP} convention. * * @param decimalPlaces the number of decimal places to round to, from 0 to 255 inclusive * @return the rounding convention * @throws IllegalArgumentException if the decimal places is invalid */ public static Rounding ofDecimalPlaces(int decimalPlaces) { return HalfUpRounding.ofDecimalPlaces(decimalPlaces); }
/** * Obtains an instance that rounds to the number of minor units in the currency. * <p> * This returns a convention that rounds for the specified currency. * Rounding follows the normal {@link RoundingMode#HALF_UP} convention. * * @param currency the currency * @return the rounding convention */ public static Rounding of(Currency currency) { return HalfUpRounding.ofDecimalPlaces(currency.getMinorUnitDigits()); }
public void test_ofDecimalPlaces_invalid() { assertThrowsIllegalArg(() -> HalfUpRounding.ofDecimalPlaces(-1)); assertThrowsIllegalArg(() -> HalfUpRounding.ofDecimalPlaces(257)); }
public void test_serialization() { HalfUpRounding test = HalfUpRounding.ofDecimalPlaces(4); assertSerialization(test); }
@DataProvider(name = "round") public static Object[][] data_round() { return new Object[][] { {HalfUpRounding.ofDecimalPlaces(2), 12.3449, 12.34}, {HalfUpRounding.ofDecimalPlaces(2), 12.3450, 12.35}, {HalfUpRounding.ofDecimalPlaces(2), 12.3451, 12.35}, {HalfUpRounding.ofDecimalPlaces(2), 12.3500, 12.35}, {HalfUpRounding.ofDecimalPlaces(2), 12.3549, 12.35}, {HalfUpRounding.ofDecimalPlaces(2), 12.3550, 12.36}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3424, 12.340}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3425, 12.345}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3426, 12.345}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3449, 12.345}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3450, 12.345}, {HalfUpRounding.ofFractionalDecimalPlaces(2, 2), 12.3451, 12.345}, }; }
public void test_ofDecimalPlaces() { HalfUpRounding test = HalfUpRounding.ofDecimalPlaces(4); assertEquals(test.getDecimalPlaces(), 4); assertEquals(test.getFraction(), 0); assertEquals(test.toString(), "Round to 4dp"); assertEquals(Rounding.ofDecimalPlaces(4), test); }
public void test_ofDecimalPlaces_big() { HalfUpRounding test = HalfUpRounding.ofDecimalPlaces(40); assertEquals(test.getDecimalPlaces(), 40); assertEquals(test.getFraction(), 0); assertEquals(test.toString(), "Round to 40dp"); assertEquals(Rounding.ofDecimalPlaces(40), test); }
public void coverage() { HalfUpRounding test = HalfUpRounding.ofDecimalPlaces(4); coverImmutableBean(test); HalfUpRounding test2 = HalfUpRounding.ofFractionalDecimalPlaces(4, 32); coverBeanEquals(test, test2); }