@Override public HalfUpRounding build() { return new HalfUpRounding( decimalPlaces, fraction); }
private Object readResolve() throws ObjectStreamException { return new HalfUpRounding(decimalPlaces, fraction); }
/** * Obtains an instance from the number of decimal places and fraction. * <p> * This returns a convention that rounds to a fraction of the specified number of decimal places. * Rounding follows the normal {@link RoundingMode#HALF_UP} convention. * <p> * For example, to round to the nearest 1/32nd of the 4th decimal place, call * this method with the arguments 4 and 32. * * @param decimalPlaces the number of decimal places to round to, from 0 to 255 inclusive * @param fraction the fraction of the last decimal place, such as 32 for 1/32, from 0 to 256 inclusive * @return the rounding convention * @throws IllegalArgumentException if the decimal places or fraction is invalid */ public static HalfUpRounding ofFractionalDecimalPlaces(int decimalPlaces, int fraction) { return new HalfUpRounding(decimalPlaces, fraction); }
/** * 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 HalfUpRounding ofDecimalPlaces(int decimalPlaces) { if (decimalPlaces >= 0 && decimalPlaces < 16) { return CACHE[decimalPlaces]; } return new HalfUpRounding(decimalPlaces, 1); }