Java BigDecimal Format formatDecimal(BigDecimal b)

Here you can find the source of formatDecimal(BigDecimal b)

Description

format Decimal

License

Open Source License

Declaration

public static String formatDecimal(BigDecimal b) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.math.BigInteger;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    public static String formatDecimal(BigDecimal b) {
        if (b == null) {
            return null;
        }/*from w ww .ja va  2 s .  c  om*/
        Locale loc = new Locale("nl", "NL", "EURO");
        NumberFormat n = NumberFormat.getCurrencyInstance(loc);
        double doublePayment = b.doubleValue();
        String s = n.format(doublePayment);
        return s;
    }

    public static String formatDecimal(BigInteger b) {

        Locale loc = new Locale("nl", "NL", "EURO");
        NumberFormat n = NumberFormat.getCurrencyInstance(loc);
        double doublePayment = b.doubleValue();
        n.setMaximumFractionDigits(0);
        String s = n.format(doublePayment);
        return s;
    }

    public static String format(int amount) {
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
        otherSymbols.setDecimalSeparator(',');
        otherSymbols.setGroupingSeparator('.');
        DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
        return df.format(amount);
    }

    public static String format(BigInteger amount) {
        if (amount == null) {
            return null;
        }
        DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
        otherSymbols.setDecimalSeparator(',');
        otherSymbols.setGroupingSeparator('.');
        DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
        return df.format(amount);
    }
}

Related

  1. formatBigDecimal(BigDecimal value, char thousandSep, char decimalPoint, int numDecimals)
  2. formatBigDecimal(String value)
  3. formatBigDecimalWithPrecise(BigDecimal number)
  4. formatCents(int cents)
  5. formatCUBRIDNumber(BigDecimal value)
  6. formatDecimal(BigDecimal num)
  7. formatDecimal(BigDecimal number, int maxFractionDigits, int minFractionDigits)
  8. formatDecimalCost(BigDecimal value)
  9. formatDigit(double value, int scale)