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

BigDecimalformatNumberStr(String numberStr, Integer scale)
format Number Str
BigDecimal bigVal = null;
try {
    bigVal = new BigDecimal(numberStr);
    if (null == scale)
        return bigVal;
    return bigVal.setScale(scale, BigDecimal.ROUND_HALF_UP);
} catch (Exception e) {
    return null;
...
StringformatNumer(BigDecimal value, int decimalPlaces, Locale locale, boolean roundCommercial)
format Numer
DecimalFormat df = getDecimalFormat(decimalPlaces, locale);
if (roundCommercial) {
    return df.format(roundCommercial(value, decimalPlaces));
return df.format(value);
StringformatoDecimal(String tipo, BigDecimal valor)
formato Decimal
String mascara = "0.";
if (tipo.equals("Q")) {
    for (int i = 0; i < DECIMAL_QUANTIDADE; i++) {
        mascara += "0";
} else if (tipo.equals("V")) {
    for (int i = 0; i < DECIMAL_VALOR; i++) {
        mascara += "0";
...
StringformatPercent(BigDecimal percent)
format Percent
return df.format(Double.parseDouble(percent.toString())) + " %";
StringformatPercentage(BigDecimal percentage)
Formats a BigDecimal representing a percentage into a string
if (percentage == null)
    return "";
return percentageDecimalFormat.format(percentage);
DoubleformatPercentDecimalDouble(Object input)
format Percent Decimal Double
if (checkInput(input)) {
    BigDecimal bd1 = new BigDecimal(input.toString());
    BigDecimal bd2 = new BigDecimal("100"); 
    return bd1.multiply(bd2).doubleValue();
return null;
StringformatQuantity(BigDecimal quantity)
Formats an BigDecimal representing a quantity into a string
if (quantity == null)
    return "";
else
    return quantityDecimalFormat.format(quantity);
StringformatQuantity(BigDecimal quantity)
format Quantity
return trim(quantity.toPlainString().replace('.', ','));
StringformatRate(BigDecimal rate)
format Rate
return rate.multiply(new BigDecimal(100)).toPlainString() + "%";
StringformatRateForDisplay(BigDecimal rate)
format Rate For Display
String outputString = "0.0000";
if (null != rate) {
    if (BigDecimal.ZERO.setScale(10, RoundingMode.HALF_UP)
            .compareTo(rate.setScale(10, RoundingMode.HALF_UP)) == 0) {
    } else {
        BigDecimal tempRate = rate.setScale(4, RoundingMode.HALF_UP);
        if (BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP).compareTo(tempRate) == 0) {
            outputString = rate.toPlainString(); 
...