/** * Returns a new {@code BigDecimal} instance with the specified scale. * <p> * If the new scale is greater than the old scale, then additional zeros are * added to the unscaled value. In this case no rounding is necessary. * <p> * If the new scale is smaller than the old scale, then trailing digits are * removed. If these trailing digits are not zero, then the remaining * unscaled value has to be rounded. For this rounding operation the * specified rounding mode is used. * * @param newScale * scale of the result returned. * @param roundingMode * rounding mode to be used to round the result. * @return a new {@code BigDecimal} instance with the specified scale. * @throws IllegalArgumentException * if {@code roundingMode} is not a valid rounding mode. * @throws ArithmeticException * if {@code roundingMode == ROUND_UNNECESSARY} and rounding is * necessary according to the given scale. */ public BigDecimal setScale(int newScale, int roundingMode) { return setScale(newScale, RoundingMode.valueOf(roundingMode)); }
/** * Returns a new {@code BigDecimal} whose value is {@code this / divisor}. * The scale of the result is the scale of {@code this}. If rounding is * required to meet the specified scale, then the specified rounding mode * {@code roundingMode} is applied. * * @param divisor * value by which {@code this} is divided. * @param roundingMode * rounding mode to be used to round the result. * @return {@code this / divisor} rounded according to the given rounding * mode. * @throws NullPointerException * if {@code divisor == null}. * @throws IllegalArgumentException * if {@code roundingMode} is not a valid rounding mode. * @throws ArithmeticException * if {@code divisor == 0}. * @throws ArithmeticException * if {@code roundingMode == ROUND_UNNECESSARY} and rounding is * necessary according to the scale of this. */ public BigDecimal divide(BigDecimal divisor, int roundingMode) { return divide(divisor, scale, RoundingMode.valueOf(roundingMode)); }
/** * Returns a new {@code BigDecimal} whose value is {@code this / divisor}. * As scale of the result the parameter {@code scale} is used. If rounding * is required to meet the specified scale, then the specified rounding mode * {@code roundingMode} is applied. * * @param divisor * value by which {@code this} is divided. * @param scale * the scale of the result returned. * @param roundingMode * rounding mode to be used to round the result. * @return {@code this / divisor} rounded according to the given rounding * mode. * @throws NullPointerException * if {@code divisor == null}. * @throws IllegalArgumentException * if {@code roundingMode} is not a valid rounding mode. * @throws ArithmeticException * if {@code divisor == 0}. * @throws ArithmeticException * if {@code roundingMode == ROUND_UNNECESSARY} and rounding is * necessary according to the given scale. */ public BigDecimal divide(BigDecimal divisor, int scale, int roundingMode) { return divide(divisor, scale, RoundingMode.valueOf(roundingMode)); }
this.roundingMode = RoundingMode.valueOf(s.substring(roundingModeStart));
private MathContext createMathContext(Long precision, String roundingMode){ if (precision == null) { precision = Long.valueOf(0); } RoundingMode rm = RoundingMode.HALF_UP; if (!StringUtils.isEmpty(roundingMode) || roundingMode != null) { rm = RoundingMode.valueOf(roundingMode); } return new MathContext(precision.intValue(), rm); }
private MathContext createMathContextLong(Long precision, String roundingMode){ if (precision == null) { precision = Long.valueOf(0); } else { Double pow = pow(10, precision); precision = precision * pow.longValue(); } RoundingMode rm = RoundingMode.HALF_UP; if (!StringUtils.isEmpty(roundingMode) || roundingMode != null) { rm = RoundingMode.valueOf(roundingMode); } return new MathContext(precision.intValue(), rm); } }
@UserFunction @Description("apoc.math.round(value,[prec],mode=[CEILING,FLOOR,UP,DOWN,HALF_EVEN,HALF_DOWN,HALF_UP,DOWN,UNNECESSARY])") public Double round(@Name("value") Double value, @Name(value = "precision",defaultValue = "0") long precision, @Name(value = "mode",defaultValue = "HALF_UP") String mode) { if (value == null) return null; return BigDecimal.valueOf(value).setScale((int)precision, RoundingMode.valueOf(mode)).doubleValue(); }
@Override public void afterPropertiesSet() throws Exception { roundingMode = RoundingMode.valueOf(roundingModeName); }
val z1 = BigDecimal(1, new java.math.MathContext( 40, java.math.RoundingMode.valueOf( scala.math.BigDecimal.RoundingMode.HALF_UP.toString))) val z40 = BigDecimal(0, new java.math.MathContext( 40, java.math.RoundingMode.valueOf( scala.math.BigDecimal.RoundingMode.HALF_UP.toString)))
/** For backward compatibility */ public static Double round(Double x, int scale, int rounding) { return round(x, scale, RoundingMode.valueOf(rounding)); }
/** For backward compatibility */ public static BigDecimal round(BigDecimal x, int scale, int rounding) { return round(x, scale, RoundingMode.valueOf(rounding)); }
private static RoundingMode getRoundingMode(Ruby runtime) { return RoundingMode.valueOf((int) bigDecimalVar(runtime, "vpRoundingMode")); }
/** For backward compatibility */ public static Float round(Float x, int scale, int rounding) { return round(x, scale, RoundingMode.valueOf(rounding)); }
/** For backward compatibility */ public static Double round(Double x, int scale, int rounding) { return round(x, scale, RoundingMode.valueOf(rounding)); }
/** For backward compatibility */ public static BigDecimal round(BigDecimal x, int scale, int rounding) { return round(x, scale, RoundingMode.valueOf(rounding)); }
private static RoundingMode getRoundingMode(Ruby runtime) { return RoundingMode.valueOf((int) bigDecimalVar(runtime, "vpRoundingMode")); }
private MonetaryContext createMonetaryContextNonNullConfig(Map<String, String> config, int prec) { String value = config.get("org.javamoney.moneta.Money.defaults.roundingMode"); RoundingMode rm = Objects.nonNull(value) ? RoundingMode.valueOf(value .toUpperCase(Locale.ENGLISH)) : RoundingMode.HALF_UP; MonetaryContext mc = MonetaryContextBuilder.of(Money.class).setPrecision(prec).set(rm).set(Money.class).build(); Logger.getLogger(DefaultMonetaryContextFactory.class.getName()).info("Using custom MathContext: precision=" + prec + ", roundingMode=" + rm); return mc; } }
private static RoundingMode getRoundingMode(Ruby runtime) { RubyFixnum roundingMode = (RubyFixnum)runtime.getClass("BigDecimal") .searchInternalModuleVariable("vpRoundingMode"); return RoundingMode.valueOf((int)roundingMode.getLongValue()); }
private RoundingMode getRoundingMode(Ruby runtime) { RubyFixnum roundingMode = (RubyFixnum)runtime.fastGetClass("BigDecimal") .searchInternalModuleVariable("vpRoundingMode"); return RoundingMode.valueOf((int)roundingMode.getLongValue()); }
private static RoundingMode getRoundingMode(Ruby runtime) { RubyFixnum roundingMode = (RubyFixnum)runtime.getClass("BigDecimal") .searchInternalModuleVariable("vpRoundingMode"); return RoundingMode.valueOf((int)roundingMode.getLongValue()); }