Java Utililty Methods Number Format Pattern

List of utility methods to do Number Format Pattern

Description

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

Method

BigDecimalgetBigDecimalFromString(String numericValue, String numberFormat)
get Big Decimal From String
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator(numberFormat.charAt(0));
symbols.setDecimalSeparator(numberFormat.charAt(1));
DecimalFormat formatter = new DecimalFormat();
formatter.setDecimalFormatSymbols(symbols);
formatter.setGroupingSize(3);
formatter.setMinimumIntegerDigits(1);
formatter.setMaximumIntegerDigits(Integer.MAX_VALUE);
...
StringgetDataFormat(final boolean grouped, final boolean isFloat, int declen)
get Data Format
DecimalFormat nf = new DecimalFormat();
nf.setGroupingUsed(grouped);
if (!isFloat)
    declen = 0;
nf.setMaximumFractionDigits(declen);
nf.setMinimumFractionDigits(declen);
return nf.toPattern();
DecimalFormatgetDefaultDecimalFormat()
Gets a default decimal format that should be used for formatting decimal values.
final DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
decimalFormatSymbols.setDecimalSeparator('.');
final DecimalFormat format = new DecimalFormat("#0.000", decimalFormatSymbols);
format.setGroupingUsed(false);
return format;
NumberFormatgetExponentialFormat(int precision)
Return exponential number format.
int absPrecision = Math.abs(precision);
NumberFormat numberFormat = expFormatCacheMap.get(absPrecision);
if (numberFormat == null) {
    final StringBuffer pattern = new StringBuffer(10);
    pattern.append("0"); 
    if (precision > 0) {
        pattern.append(".");
    for (int i = 0; i < precision; ++i) {
        pattern.append('0');
    pattern.append("E0"); 
    numberFormat = new DecimalFormat(pattern.toString());
    expFormatCacheMap.put(absPrecision, numberFormat);
return numberFormat;
StringgetF(String tStr, String formate)
get F
try {
    df.applyPattern(formate);
    return format(tStr);
} catch (Exception e) {
    return tStr;
DecimalFormatgetFloatFormat()
get Float Format
return FLOAT_FORMAT;
NumberFormatgetFormat()
get Format
return new DecimalFormat("#0.00000##########################");
DecimalFormatgetFormat(int decimals)
Returns the decimal formatter, which has a number of decimals.
DecimalFormat df;
df = (DecimalFormat) DecimalFormat.getInstance(Locale.getDefault());
DecimalFormatSymbols dsym = df.getDecimalFormatSymbols();
char decimalSeparator = dsym.getDecimalSeparator();
StringBuffer pattern = new StringBuffer("0");
pattern.append(decimalSeparator);
for (int i = 0; i < decimals; i++)
    pattern.append("0");
...
NumberFormatgetFormat(int nbDecimale)
get Format
NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(nbDecimale);
format.setMinimumFractionDigits(nbDecimale);
format.setGroupingUsed(true);
return format;
DecimalFormatgetFormatedInt(int maxValue)
get Formated Int
String ret = "";
int zeros = (int) Math.floor(Math.log10(maxValue)) + 1;
for (int i = 0; i < zeros; i++) {
    ret += "0";
return new DecimalFormat(ret);