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

BigDecimalformatBigDecimal(String value)
Checks if the value can safely be converted to a BigDecimal.
if (value == null) {
    return null;
try {
    return new BigDecimal(value);
} catch (NumberFormatException e) {
    return null;
StringformatBigDecimalWithPrecise(BigDecimal number)
format bigdecimal to string
String result = "";
NumberFormat nbf = new DecimalFormat("#,##0.00");
if (number != null) {
    result = nbf.format(number.doubleValue());
return result;
StringformatCents(int cents)
format Cents
return centsToUnit(cents).toPlainString();
StringformatCUBRIDNumber(BigDecimal value)
Format number to fit for CUBRID numeric type.
return new DecimalFormat(DEFAULT_NUMERIC_FORMAT).format(value);
StringformatDecimal(BigDecimal b)
format Decimal
if (b == null) {
    return null;
Locale loc = new Locale("nl", "NL", "EURO");
NumberFormat n = NumberFormat.getCurrencyInstance(loc);
double doublePayment = b.doubleValue();
String s = n.format(doublePayment);
return s;
...
StringformatDecimal(BigDecimal num)
format Decimal
return NumberFormat.getInstance(Locale.US).format(num);
StringformatDecimal(BigDecimal number, int maxFractionDigits, int minFractionDigits)
Formats a number so that the number of digits in the fraction portion of it is bound by a maximum value and a minimum value.
DecimalFormat df = new DecimalFormat();
df.setGroupingUsed(false);
df.setMaximumFractionDigits(maxFractionDigits);
df.setMinimumFractionDigits(minFractionDigits);
return df.format(number);
StringformatDecimalCost(BigDecimal value)
format Decimal Cost
Currency currency = Currency.getInstance(Locale.getDefault());
NumberFormat fmt = DecimalFormat.getInstance();
fmt.setMinimumFractionDigits(2);
fmt.setMaximumFractionDigits(2);
return currency.getSymbol() + fmt.format(value);
doubleformatDigit(double value, int scale)
format Digit
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
double d = bd.doubleValue();
bd = null;
return d;
StringformatDouble(double d)
format Double
String[] plain = printDouble(d).split("\\.");
String formatted = "";
while (plain[0].length() >= 4) {
    formatted = "'" + plain[0].substring(plain[0].length() - 3) + formatted;
    plain[0] = plain[0].substring(0, plain[0].length() - 3);
formatted = plain[0] + formatted;
if ((plain.length > 1) && (tryParse(plain[1], 0) != 0)) {
...