Java Utililty Methods BigDecimal

List of utility methods to do BigDecimal

Description

The list of methods to do BigDecimal are organized into topic(s).

Method

BigDecimalgetWithoutTrailingZeroes(@Nullable final BigDecimal aValue)
Get the passed BigDecimal without any trailing zeroes.
if (aValue == null)
    return null;
if (BigDecimal.ZERO.compareTo(aValue) == 0)
    return BigDecimal.ZERO;
final BigDecimal ret = aValue.stripTrailingZeros();
return ret.scale() >= 0 ? ret : ret.setScale(0);
inthash(BigDecimal bd)
hash
if (bd == null)
    return NULL_HASH;
return bd.hashCode();
booleanhasSignedChanged(final BigDecimal v1, final BigDecimal v2)
has Signed Changed
return signum(v1) != signum(v2);
StringhtmlFooter(String providerNo, int count, BigDecimal total)
html Footer
StringBuilder htmlFooter = new StringBuilder();
htmlFooter.append(
        "<tr><td colspan='11' class='bodytext'>&nbsp;</td>  </tr>  <tr>    <td colspan='5' class='bodytext'>Billing No: ");
htmlFooter.append(providerNo);
htmlFooter.append(": ");
htmlFooter.append(count);
htmlFooter.append(" RECORDS PROCESSED</td>    <td colspan='6' class='bodytext'>TOTAL: ");
htmlFooter.append(total);
...
StringhumanReadableByteCount(BigDecimal bytes, Boolean si)
human Readable Byte Count
return humanReadableByteCount(bytes.doubleValue(), si);
BigDecimalincRatio(BigDecimal o1, BigDecimal o2)
calc a increase ratio between two BigDecimal;
double d1, d2;
if (o1 == null && o2 == null) {
    return new BigDecimal(0);
if (o2 == null || o2.intValue() == 0) {
    return new BigDecimal(100);
if (o1 != null) {
...
BigDecimalintToBigDecimal(int i)
int To Big Decimal
BigInteger bigint = BigInteger.valueOf(i);
BigDecimal bigdec = new BigDecimal(bigint);
return bigdec;
intintValue(BigDecimal a)
int Value
if (a == null) {
    return 0;
return a.intValue();
BigDecimalinverse(final BigDecimal amount)
inverse
return amount.equals(BigDecimal.ZERO) ? amount : BigDecimal.ONE.divide(amount, RoundingMode.HALF_EVEN);
BigDecimalinvert(BigDecimal d)
Divide 1 by the specified BigDecimal.
return divide(BigDecimal.ONE, d);