Java Number Format Pattern getFormatter(String pattern)

Here you can find the source of getFormatter(String pattern)

Description

Create a DecimalFormat instance for the given pattern that uses '.'

License

Open Source License

Parameter

Parameter Description
pattern the pattern string

Exception

Parameter Description
IllegalArgumentException if the given pattern is invalid
NullPointerException if the given pattern is <code>null</code>

Return

A for the given pattern

Declaration

public static DecimalFormat getFormatter(String pattern) throws IllegalArgumentException 

Method Source Code


//package com.java2s;
/*/*from   w  w  w .jav a2s . co m*/
 * Copyright (c) 2016 wetransform GmbH
 * 
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution. If not, see <http://www.gnu.org/licenses/>.
 * 
 * Contributors:
 *     wetransform GmbH <http://www.wetransform.to>
 */

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
    /**
     * Create a {@link DecimalFormat} instance for the given pattern that uses
     * '.' as the decimal separator.
     * 
     * @param pattern the pattern string
     * @return A {@link DecimalFormat} for the given pattern
     * @throws IllegalArgumentException if the given pattern is invalid
     * @throws NullPointerException if the given pattern is <code>null</code>
     * @see DecimalFormat
     */
    public static DecimalFormat getFormatter(String pattern) throws IllegalArgumentException {
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator('.');
        return new DecimalFormat(pattern, symbols);
    }
}

Related

  1. getFormattedQuantity(String qty, int len, String pad)
  2. getFormattedString4Digits(String number, String pattern)
  3. getFormatter()
  4. getFormatter()
  5. getFormatter(int precision)
  6. getFormatTwoPoint(float param)
  7. getFormatWithMinimumDecimals(final int minimumDecimals, final int maximumDecimals)
  8. getGeographicPositionFormatter()
  9. getIntegerFormat()