Java Utililty Methods BigDecimal Format

List of utility methods to do BigDecimal Format

Description

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

Method

Stringformat(BigDecimal number, String format)
Method that formats the given BigDecimal into a String with the specified format
if (number == null)
    return null;
DecimalFormat snf = new DecimalFormat(format);
return snf.format(number.doubleValue());
Stringformat(final BigDecimal bd)
return a Number formatted or empty string if null.
return bd != null ? NUMBER_FORMAT.format(bd) : "";
Stringformat(Object value, Integer precision)
format
Double number = Double.valueOf(0.0D);
if (isDigit(value)) {
    number = new Double(value.toString());
precision = Integer.valueOf((precision == null) || (precision.intValue() < 0) ? 2 : precision.intValue());
BigDecimal bigDecimal = new BigDecimal(number.doubleValue());
return bigDecimal.setScale(precision.intValue(), 4).toString();
Stringformat(String pattern, final double secondInDouble)
Format the duration.
if ((Double.isNaN(secondInDouble)) || (secondInDouble == 0)) {
    return "0 second";
boolean isDayCalculated = false;
boolean isHourCalculated = false;
boolean isMinuteCalculated = false;
boolean isSecondCalculated = false;
pattern = pattern.toLowerCase();
...
Stringformat2Scale(BigDecimal obj)
format Scale
if (obj != null) {
    return obj.setScale(2, ROUNDING_MODE).toPlainString();
} else {
    return "";
Stringformat2String(BigDecimal bd)
format String
if (bd != null) {
    bd = bd.setScale(2, RoundingMode.HALF_UP);
    return bd.toString();
} else {
    return null;
Stringformat_BigDecimal(BigDecimal decimal, Integer scale)
forma Big Decimal
if (decimal == null) {
    return null;
if (scale == null) {
    return decimal.toPlainString();
return decimal.setScale(scale, RoundingMode.HALF_UP).toPlainString();
StringformatAmount(BigDecimal amount)
format Amount
return new DecimalFormat("#0.00").format(amount);
StringformatAmount(BigDecimal amount)
format Amount
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(0);
nf.setGroupingUsed(false);
return nf.format(amount);
StringformatAmount(final BigDecimal number)
format Amount
NumberFormat formatter = new DecimalFormat(".00");
return formatter.format(number);