public static DecimalFormat scale2Format(final int scale, final RoundingMode roundingMode) { final String cacheKey = scale + roundingMode.name(); DecimalFormat result = DECIMAL_FORMAT_MAP.get(cacheKey); if (result == null) { result = new DecimalFormat(scale2FormatStr(scale)); result.setRoundingMode(roundingMode); DECIMAL_FORMAT_MAP.put(cacheKey, result); } return result; }
public void testRound(double value, double expected, RoundingMode mode) { testCall(db, "RETURN apoc.math.round({value},{prec},{mode}) as value",map("value",value,"prec",0,"mode",mode.name()), (row) -> assertEquals(expected,row.get("value"))); }
@Override public Object toJson() { if (getDecimalFormat() == null) { return null; } JSONObject json = new JSONObject(); json.put("pattern", getDecimalFormat().toPattern()); json.put("multiplier", getDecimalFormat().getMultiplier()); json.put("roundingMode", getDecimalFormat().getRoundingMode().name()); return json; }
public CodegenExpression initCtorScoped() { if (mathContext == null) { return constantNull(); } return newInstance(MathContext.class, constant(mathContext.getPrecision()), enumValue(RoundingMode.class, mathContext.getRoundingMode().name())); }