Java Locale Format formatNumber(Object number, String pattern, Locale locale)

Here you can find the source of formatNumber(Object number, String pattern, Locale locale)

Description

format number by pattern and locale

License

Open Source License

Parameter

Parameter Description
number number
pattern pattern
locale locale

Return

String

Declaration

public static String formatNumber(Object number, String pattern, Locale locale) 

Method Source Code

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

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

import java.util.*;

public class Main {
    /**// w  ww.jav a 2  s .c o  m
     * format number by pattern and locale
     *
     * @param number  number
     * @param pattern pattern
     * @param locale  locale
     * @return String
     */
    public static String formatNumber(Object number, String pattern, Locale locale) {
        if (number instanceof String) {
            return (String) number;
        }

        DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
        NumberFormat parser = new DecimalFormat(pattern, decimalFormatSymbols);
        return parser.format(number);
    }
}

Related

  1. formatNumber(long value)
  2. formatNumber(Number num)
  3. formatNumber(Number number)
  4. formatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)
  5. formatNumber(Number value, String format)
  6. formatNumber(Object value, Locale locale)
  7. formatNumber(Object value, String numberFormat)
  8. formatNumberSameWidth(final double v)
  9. formatNumberUk(double inNumber, int inDecimalPlaces)