Java Number Format Pattern isDecimalFormatValid(final String pattern)

Here you can find the source of isDecimalFormatValid(final String pattern)

Description

Validates a DecimalFormat decimal format .

License

Open Source License

Parameter

Parameter Description
pattern The candidate String string to test.

Return

True if the argument is a valid decimal format , and False otherwise.

Declaration

public static boolean isDecimalFormatValid(final String pattern) 

Method Source Code

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

import java.text.DecimalFormat;

public class Main {
    /**/*from  www.  j a va 2  s  .  c  om*/
     * Validates a {@link DecimalFormat decimal format}.
     * 
     * @param pattern
     *            The candidate {@link String string} to test.
     * @return <code>True</code> if the argument is a valid {@link DecimalFormat
     *         decimal format}, and <code>False</code> otherwise.
     */
    public static boolean isDecimalFormatValid(final String pattern) {
        boolean result = false;
        try {
            new DecimalFormat(pattern);
            result = true; // pattern must be valid not to have
                           // thrown
                           // an exception
        } catch (Throwable e) {
        }
        return result;
    }
}

Related

  1. getUSNumberFormatter()
  2. getValueFormatted(String name, String value)
  3. getValueFormatter()
  4. getZeroDecimalFormat()
  5. isDecimalFormat(DecimalFormat decimalFormat)
  6. matchOptionalFormatting(Number number, String formatting, StringBuffer outputTo)
  7. normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision)
  8. objectToString(Object obj, DecimalFormat fmt)
  9. print(float[] array, NumberFormat nf)