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

StringformatManey(BigDecimal date)
format Maney
java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");
return df.format(date);
StringformatMoney(BigDecimal money, int scale, double divisor)
format Money
if (divisor == 0) {
    return "0.00";
if (scale < 0) {
    return "0.00";
BigDecimal divisorBD = new BigDecimal(divisor);
return money.divide(divisorBD, scale, RoundingMode.HALF_UP).toString();
...
StringformatMoney(long value)
format Money
return new BigDecimal(value).divide(new BigDecimal(100)).setScale(2).toString();
StringformatNoDecimalPoint(double amt)
format No Decimal Point
StringBuffer ret = new StringBuffer();
String tmp = "";
try {
    tmp = new Long(new BigDecimal(amt).longValue()).toString();
} catch (NumberFormatException e) {
    return "";
int index = tmp.indexOf(".");
...
StringformatNumber(double number)
Converts numbers that include exponents into a regular number.
String numString = Double.toString(number);
int idx = numString.indexOf((int) 'E');
if (idx == -1) {
    if (numString.endsWith(".0")) {
        numString = numString.substring(0, numString.length() - 2);
    return numString;
int exponent = Integer.parseInt(numString.substring(idx + 1));
int precision = idx - 1;
if (exponent > 0 && exponent == precision) {
    precision++;
BigDecimal bd = new BigDecimal(number, new MathContext(precision));
return bd.toPlainString();
StringformatNumber(String format, BigDecimal number)
format Number
if (format == null)
    return "" + number;
DecimalFormat df = new DecimalFormat(format);
String retVal = null;
try {
    retVal = df.format(number);
} catch (Exception e) {
    retVal = "" + number;
...
StringformatNumberByMaxFrac(BigDecimal number, int val)
format Number By Max Frac
if (number == null)
    return "";
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(val);
return nf.format(number);
StringformatNumberByMaxFracUseGrp(BigDecimal number, int val)
format Number By Max Frac Use Grp
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(val);
nf.setGroupingUsed(true);
return nf.format(number);
StringformatNumberCroreFormat(final BigDecimal num)
Formats given number in Indian format (CRORE format).
final double absAmount = num.abs().doubleValue(); 
final long numLakhs = (long) (absAmount / 100000); 
final double numThousands = absAmount - (numLakhs * 100000); 
final DecimalFormat formatter = new DecimalFormat("#,##");
final String firstPart = (num.doubleValue() < 0 ? "-" : "")
        + (numLakhs > 0 ? formatter.format(numLakhs) + "," : "");
formatter.applyPattern("00,000.00");
return (firstPart + formatter.format(numThousands));
...
doubleformatNumberDouble(Double amount, int scale)
format Number Double
if (null == amount)
    amount = 0.00;
BigDecimal b = new BigDecimal(amount).setScale(scale, BigDecimal.ROUND_HALF_UP);
return b.doubleValue();