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

NumberFormatgetNumberFormatInstanceFor2DecimalDigits()
get Number Format Instance For Decimal Digits
NumberFormat numberFormatFor2DecimalDigits = NumberFormat.getInstance();
numberFormatFor2DecimalDigits.setMaximumFractionDigits(2);
return numberFormatFor2DecimalDigits;
NumberFormatgetNumberFormatter()
get Number Formatter
if (numberFormatter == null) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols();
    otherSymbols.setDecimalSeparator('.');
    numberFormatter = new DecimalFormat("0.0#######", otherSymbols);
return numberFormatter;
DecimalFormatgetNumberFormatter(final String format)
get Number Formatter
ThreadLocal<DecimalFormat> threadLocal = decimalFormatters.get(format);
if (threadLocal == null) {
    threadLocal = new ThreadLocal<DecimalFormat>() {
        @Override
        protected DecimalFormat initialValue() {
            return new DecimalFormat(format);
    };
...
NumberFormatgetNumberFraction2Format(final Locale locale)
get Number Fraction Format
final NumberFormat format = NumberFormat.getNumberInstance(locale);
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
return format;
intgetNumberOfDays(String year, String month)
get Number Of Days
GregorianCalendar calendar = null;
SimpleDateFormat sdf = null;
try {
    int yyyy = Integer.parseInt(year);
    int mm = Integer.parseInt(month);
    calendar = new GregorianCalendar(yyyy, mm, 0);
    sdf = new SimpleDateFormat("dd");
    return Integer.parseInt(sdf.format(calendar.getTime()));
...
intgetNumberStyleAsInt(String style)
Checks a string to see if it matches one of the standard NumberFormat style patterns: number, currency, percent, integer, or default.
if (style == null || style.length() < 6 || style.length() > 8) {
    return -1;
if (style.equalsIgnoreCase("default")) {
    return STYLE_NUMBER;
if (style.equalsIgnoreCase("number")) {
    return STYLE_NUMBER;
...
NumberFormatgetOneFractionDigitNumberFormat()
get One Fraction Digit Number Format
NumberFormat result = NumberFormat.getInstance();
result.setMaximumFractionDigits(1);
return result;
DecimalFormatgetPriceFormat()
get Price Format
return PRICE_FORMAT;
DecimalFormatgetScientificFormatter(int precision)
get Scientific Formatter
DecimalFormat df = scientificFormatters.get(precision);
if (df == null) {
    StringBuffer format = new StringBuffer("0.");
    for (int i = 0; i < precision; i++)
        format.append("#");
    format.append("E0");
    df = new DecimalFormat(format.toString());
    scientificFormatters.put(precision, df);
...
chargetSeparator(final NumberFormat format)
Returns the separator to use between numbers.
if (format instanceof DecimalFormat) {
    final char c = ((DecimalFormat) format).getDecimalFormatSymbols().getDecimalSeparator();
    if (c == ',') {
        return ';';
return ',';