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

StringgetNumberComma(String number)
Insert comma to String
NumberFormat fmt = NumberFormat.getInstance();
String strNumber = fmt.format(Double.valueOf(number));
return strNumber;
NumberFormatgetNumberFormat()
get Number Format
NumberFormat nf = NumberFormat.getIntegerInstance(SITEMAP_LOCALE);
nf.setMinimumFractionDigits(5);
return nf;
NumberFormatgetNumberFormat()
get Number Format
return numberFormat;
StringgetNumberFormat(BigDecimal num, final int digits)
get Number Format
String thenum = "";
if (num == null) {
    num = new BigDecimal(0);
try {
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(digits);
    nf.setMinimumFractionDigits(digits);
...
doublegetNumberFormat(double d)
format the double number
DecimalFormat format = new DecimalFormat("###0.000000");
String str = "";
str = format.format(d);
double e = Double.parseDouble(str);
return e;
NumberFormatgetNumberFormat(final String pattern)
get Number Format
DecimalFormat df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(Locale.ENGLISH));
return df;
NumberFormatgetNumberFormat(int maximumFractionDigits)
Return a number formatter with maximum fraction digits, no grouping, locale ENGLISH.
NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
format.setMaximumFractionDigits(maximumFractionDigits);
format.setGroupingUsed(false);
return format;
NumberFormatgetNumberFormat(String format, Locale locale)
Returns a NumberFormat instance for the specified format and Locale .
if (format == null || locale == null) {
    return null;
NumberFormat nf = null;
int style = getNumberStyleAsInt(format);
if (style < 0) {
    nf = new DecimalFormat(format, new DecimalFormatSymbols(locale));
} else {
...
DecimalFormatgetNumberFormat(String localeStr)
get Number Format
DecimalFormat nf = numberformatMap.get(localeStr);
if (nf == null) {
    Locale locale = new Locale(localeStr);
    nf = (DecimalFormat) NumberFormat.getInstance(locale);
    numberformatMap.put(localeStr, nf);
return nf;
NumberFormatgetNumberFormatFromCache(Locale locale, Currency currency)
Provides a cached approach for creating NumberFormat instances.
String key = locale.toString() + currency.getCurrencyCode();
if (!FORMAT_CACHE.containsKey(key)) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);
    format.setCurrency(currency);
    FORMAT_CACHE.put(key, format);
return FORMAT_CACHE.get(key);