List of utility methods to do BigDecimal
BigDecimal | readBigDecimal(DataInput in) Reads BigDecimal value that was written via #writeBigDecimal(BigDecimal,DataOutput) . byte hint = in.readByte(); switch (hint) { case DECIMAL_ZERO: { return BigDecimal.ZERO; case DECIMAL_ONE: { return BigDecimal.ONE; case DECIMAL_TEN: { return BigDecimal.TEN; case DECIMAL_SMALL_UNSCALED: { long val = readVarLong(in); return BigDecimal.valueOf(val); case DECIMAL_SMALL_SCALED: { int scale = readVarIntUnsigned(in); long unscaled = readVarLong(in); return BigDecimal.valueOf(unscaled, scale); case DECIMAL_BIG: { int scale = readVarIntUnsigned(in); int bytesLen = readVarIntUnsigned(in); byte[] bytes = new byte[bytesLen]; in.readFully(bytes); return new BigDecimal(new BigInteger(bytes), scale); default: { throw new StreamCorruptedException( "Unexpected hint for " + BigDecimal.class.getName() + " value [hint=" + hint + ']'); |
BigDecimal | readBigDecimal(final Object object) read Big Decimal if (object != null) { return new BigDecimal((String) object); } else { return null; |
BigDecimal | releaseNull(BigDecimal amount) release Null return amount == null ? BigDecimal.ZERO : amount;
|
BigDecimal | removeTrailingZeros(final BigDecimal bd) remove Trailing Zeros if (bd.signum() == 0) { return bd.setScale(0); final String text = bd.toPlainString(); int scale = bd.scale(); for (int i = text.length() - 1; i >= 0; i--) { final char c = text.charAt(i); if (c != '0') { ... |
int | removeVAT(int priceInCents, BigDecimal vat) remove VAT return new BigDecimal(priceInCents).divide(BigDecimal.ONE.add(vat.divide(HUNDRED, 5, UP)), 5, HALF_UP) .setScale(0, HALF_UP).intValueExact(); |
BigDecimal | reverseSign(BigDecimal decimal) reverse +,- sign. return minus(decimal);
|
BigDecimal | rundeKaufmaennisch(BigDecimal bigDecimal, int stellen) kaufmaennisch runden. return bigDecimal == null ? null : bigDecimal.setScale(stellen, BigDecimal.ROUND_HALF_EVEN);
|
BigDecimal | safeAdd(BigDecimal left, BigDecimal right) A null-aware method for adding BigDecimal, but only for the right operand. return right != null ? left.add(right) : left;
|
BigDecimal | safeAddBD(BigDecimal bd1, BigDecimal bd2) safe Add BD if (bd1 == null && bd2 == null) { return ZERO; } else if (bd2 == null) { return bd1; } else if (bd1 == null) { return bd2; } else { return bd1.add(bd2); ... |
BigDecimal | safeNull(BigDecimal value) safe Null return value == null ? BigDecimal.ZERO : value;
|