Java Number Format Pattern getNumberStyleAsInt(String style)

Here you can find the source of getNumberStyleAsInt(String style)

Description

Checks a string to see if it matches one of the standard NumberFormat style patterns: number, currency, percent, integer, or default.

License

LGPL

Parameter

Parameter Description
style the string to be checked

Return

the int identifying the style pattern

Declaration

public static int getNumberStyleAsInt(String style) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    private static final int STYLE_NUMBER = 0;
    private static final int STYLE_CURRENCY = 1;
    private static final int STYLE_PERCENT = 2;
    private static final int STYLE_INTEGER = 4;

    /**//w w  w . j a v  a  2 s .co  m
     * Checks a string to see if it matches one of the standard
     * NumberFormat style patterns:
     * number, currency, percent, integer, or default.
     * if it does it will return the integer constant for that pattern.
     * if not, it will return -1.
     *
     * @param style the string to be checked
     * @return the int identifying the style pattern
     * @see NumberFormat
     */
    public static int getNumberStyleAsInt(String style) {
        // avoid needlessly running through all the string comparisons
        if (style == null || style.length() < 6 || style.length() > 8) {
            return -1;
        }
        if (style.equalsIgnoreCase("default")) {
            //NOTE: java.text.NumberFormat returns "number" instances
            //      as the default (at least in Java 1.3 and 1.4).
            return STYLE_NUMBER;
        }
        if (style.equalsIgnoreCase("number")) {
            return STYLE_NUMBER;
        }
        if (style.equalsIgnoreCase("currency")) {
            return STYLE_CURRENCY;
        }
        if (style.equalsIgnoreCase("percent")) {
            return STYLE_PERCENT;
        }
        if (style.equalsIgnoreCase("integer")) {
            return STYLE_INTEGER;
        }
        // ok, it's not any of the standard patterns
        return -1;
    }
}

Related

  1. getNumberFormatInstanceFor2DecimalDigits()
  2. getNumberFormatter()
  3. getNumberFormatter(final String format)
  4. getNumberFraction2Format(final Locale locale)
  5. getNumberOfDays(String year, String month)
  6. getOneFractionDigitNumberFormat()
  7. getPriceFormat()
  8. getScientificFormatter(int precision)
  9. getSeparator(final NumberFormat format)