/** * Returns a new {@code BigDecimal} whose value is {@code this}, rounded * according to the passed context {@code mc}. * <p> * If {@code mc.precision = 0}, then no rounding is performed. * <p> * If {@code mc.precision > 0} and {@code mc.roundingMode == UNNECESSARY}, * then an {@code ArithmeticException} is thrown if the result cannot be * represented exactly within the given precision. * * @param mc * rounding mode and precision for the result of this operation. * @return {@code this} rounded according to the passed context. * @throws ArithmeticException * if {@code mc.precision > 0} and {@code mc.roundingMode == * UNNECESSARY} and this cannot be represented within the given * precision. */ public static BigDecimal Round(BigDecimal number, MathContext mc) { var thisBD = new BigDecimal(number.UnscaledValue, number.Scale); thisBD.InplaceRound(mc); return(thisBD); }
/** * Returns a new {@code BigDecimal} whose value is {@code this * * multiplicand}. The result is rounded according to the passed context * {@code mc}. * * @param multiplicand * value to be multiplied with {@code this}. * @param mc * rounding mode and precision for the result of this operation. * @return {@code this * multiplicand}. * @throws NullPointerException * if {@code multiplicand == null} or {@code mc == null}. */ public static BigDecimal Multiply(BigDecimal value, BigDecimal multiplicand, MathContext mc) { BigDecimal result = Multiply(value, multiplicand); result.InplaceRound(mc); return(result); }