/** * Round an operand; used only if digits > 0. Does not change * {@code this}; if rounding is needed a new {@code BigDecimal} * is created and returned. * * @param mc the context to use. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. */ private BigDecimal roundOp(MathContext mc) { BigDecimal rounded = doRound(this, mc); return rounded; }
/** * Round an operand; used only if digits > 0. Does not change * {@code this}; if rounding is needed a new {@code BigDecimal} * is created and returned. * * @param mc the context to use. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. */ private BigDecimal roundOp(MathContext mc) { BigDecimal rounded = doRound(this, mc); return rounded; }
/** * Returns a {@code BigDecimal} whose value is {@code (+this)}, * with rounding according to the context settings. * * <p>The effect of this method is identical to that of the {@link * #round(MathContext)} method. * * @param mc the context to use. * @return {@code this}, rounded as necessary. A zero result will * have a scale of 0. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. * @see #round(MathContext) * @since 1.5 */ public BigDecimal plus(MathContext mc) { if (mc.precision == 0) // no rounding please return this; return doRound(this, mc); }
/** Round this BigDecimal according to the MathContext settings; * used only if precision {@literal >} 0. * * <p>WARNING: This method should only be called on new objects as * it mutates the value fields. * * @param mc the context to use. * @throws ArithmeticException if the rounding mode is * {@code RoundingMode.UNNECESSARY} and the * {@code BigDecimal} operation would require rounding. */ private void roundThis(MathContext mc) { BigDecimal rounded = doRound(this, mc); if (rounded == this) // wasn't rounded return; this.intVal = rounded.intVal; this.intCompact = rounded.intCompact; this.scale = rounded.scale; this.precision = rounded.precision; }
/** Round this BigDecimal according to the MathContext settings; * used only if precision {@literal >} 0. * * <p>WARNING: This method should only be called on new objects as * it mutates the value fields. * * @param mc the context to use. * @throws ArithmeticException if the rounding mode is * {@code RoundingMode.UNNECESSARY} and the * {@code BigDecimal} operation would require rounding. */ private void roundThis(MathContext mc) { BigDecimal rounded = doRound(this, mc); if (rounded == this) // wasn't rounded return; this.intVal = rounded.intVal; this.intCompact = rounded.intCompact; this.scale = rounded.scale; this.precision = rounded.precision; }
/** * Returns a {@code BigDecimal} whose value is {@code (+this)}, * with rounding according to the context settings. * * <p>The effect of this method is identical to that of the {@link * #round(MathContext)} method. * * @param mc the context to use. * @return {@code this}, rounded as necessary. A zero result will * have a scale of 0. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. * @see #round(MathContext) * @since 1.5 */ public BigDecimal plus(MathContext mc) { if (mc.precision == 0) // no rounding please return this; return doRound(this, mc); }
/** * Returns a {@code BigDecimal} whose value is <tt>(this × * multiplicand)</tt>, with rounding according to the context settings. * * @param multiplicand value to be multiplied by this {@code BigDecimal}. * @param mc the context to use. * @return {@code this * multiplicand}, rounded as necessary. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. * @since 1.5 */ public BigDecimal multiply(BigDecimal multiplicand, MathContext mc) { if (mc.precision == 0) return multiply(multiplicand); return doRound(this.multiply(multiplicand), mc); }
/** * Returns a {@code BigDecimal} whose value is <tt>(this × * multiplicand)</tt>, with rounding according to the context settings. * * @param multiplicand value to be multiplied by this {@code BigDecimal}. * @param mc the context to use. * @return {@code this * multiplicand}, rounded as necessary. * @throws ArithmeticException if the result is inexact but the * rounding mode is {@code UNNECESSARY}. * @since 1.5 */ public BigDecimal multiply(BigDecimal multiplicand, MathContext mc) { if (mc.precision == 0) return multiply(multiplicand); return doRound(this.multiply(multiplicand), mc); }
acc=ONE.divide(acc, workmc); return doRound(acc, mc);
acc=ONE.divide(acc, workmc); return doRound(acc, mc);
checkScale(preferredScale)); quotient = doRound(quotient, mc);
checkScale(preferredScale)); quotient = doRound(quotient, mc);