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

BigDecimalstrValueBigDecimal(Number number)
str Value Big Decimal
if (number == null) {
    return zeroBigDecimal();
return new BigDecimal(String.valueOf(number));
BigDecimaltangent(BigDecimal x)
tangent
BigDecimal sin = sine(x);
BigDecimal cos = cosine(x);
return sin.divide(cos, SCALE, BigDecimal.ROUND_HALF_UP);
BigDecimaltanto(BigDecimal r, BigDecimal n)
tanto
return r.divide(n);
BigDecimaltextToBigDecimal(String amountAsText)
text To Big Decimal
return new BigDecimal(amountAsText).setScale(DECIMAL_SCALE, ROUNDING_MODE);
inttransferDonateAmount2Point(BigDecimal donateAmount)
transfer Donate Amount Point
if (donateAmount == null) {
    return 0;
Double temp = donateAmount.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
return temp.intValue() / TEN_YUAN;
BigDecimaltryParseBigDecimal(Object val, BigDecimal defaultVal)
try Parse Big Decimal
if (val == null)
    return defaultVal;
if (val instanceof BigDecimal)
    return (BigDecimal) val;
try {
    return new BigDecimal(String.valueOf(val));
} catch (Exception e) {
    return defaultVal;
...
BigDecimaltryToStoreAsIntegerBigDecimal(Object ob)
try To Store As Integer Big Decimal
BigDecimal bigDecimal = null;
if (canBeStoredAsIntegerBigDecimal(ob)) {
    bigDecimal = new BigDecimal(ob.toString());
return bigDecimal;
BigDecimaltryToStoreAsRealBigDecimal(Object ob)
try To Store As Real Big Decimal
BigDecimal bigDecimal = null;
if (canBeStoredAsRealBigDecimal(ob)) {
    bigDecimal = new BigDecimal(ob.toString());
} else if (ob instanceof BigDecimal) {
    bigDecimal = (BigDecimal) ob;
return bigDecimal;
StringunformattedFromBigDecimal(BigDecimal n)
Convert a BigDecimal to the unformatted form.
if (n == null) {
    return "";
return n.toPlainString();
BigDecimalunformattedToBigDecimal(String str)
Convert an unformatted string to BigDecimal.
if (str == null || str.length() == 0) {
    str = "0";
BigDecimal b = new BigDecimal(str);
return b.setScale(b.scale(), BigDecimal.ROUND_HALF_UP);