/** * @return whether a BigDecimal is a valid Farrago decimal. If a BigDecimal's unscaled value * overflows a long, then it is not a valid Farrago decimal. */ public static boolean isValidDecimal(BigDecimal bd) { BigInteger usv = bd.unscaledValue(); long usvl = usv.longValue(); return usv.equals(BigInteger.valueOf(usvl)); }
public static final BigDecimal rescaleBigDecimal(BigDecimal bd, int scale) { if (bd != null) { bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP); } return bd; }