Java Utililty Methods Locale Format

List of utility methods to do Locale Format

Description

The list of methods to do Locale Format are organized into topic(s).

Method

StringformatNumber(Number num)
format Number
return getNumberFormat().format(num);
StringformatNumber(Number number)
format Number
NumberFormat format = NumberFormat.getNumberInstance(Locale.getDefault());
return format.format(number);
StringformatNumber(Number value, int minDecimals, int maxDecimals, boolean grouping, boolean dotDecimalSymbol)
format Number
DecimalFormat formatter = new DecimalFormat();
formatter.setMinimumFractionDigits(minDecimals);
formatter.setMaximumFractionDigits(maxDecimals);
if (dotDecimalSymbol) {
    formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
formatter.setGroupingUsed(grouping);
return formatter.format(value);
...
StringformatNumber(Number value, String format)
Formats an arbitrary numeric object according to the current locale.
return getNumberFormatter(format).format(value);
StringformatNumber(Object number, String pattern, Locale locale)
format number by pattern and locale
if (number instanceof String) {
    return (String) number;
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(locale);
NumberFormat parser = new DecimalFormat(pattern, decimalFormatSymbols);
return parser.format(number);
StringformatNumber(Object value, Locale locale)
format Number
NumberFormat nf = NumberFormat.getNumberInstance(locale);
String sval = new String(value.toString());
if (sval.contains("(")) {
    String[] split = sval.split("\\(");
    sval = split[1];
if (sval.contains(")")) {
    String[] split = sval.split("\\)");
...
StringformatNumber(Object value, String numberFormat)
Format a number using a valid Java format mask and the default Locale
DecimalFormat fmt = (DecimalFormat) NumberFormat.getInstance();
fmt.applyPattern(numberFormat);
return fmt.format(value);
StringformatNumberSameWidth(final double v)
Format a given number for output
return FORMATTER.format(v);
StringformatNumberUk(double inNumber, int inDecimalPlaces)
Format the given number in UK format (decimal point) to the given number of decimal places
UK_FORMAT.setMaximumFractionDigits(inDecimalPlaces);
UK_FORMAT.setMinimumFractionDigits(inDecimalPlaces);
return UK_FORMAT.format(inNumber);
StringformatNumberWithThousandSeparator(long number)
format Number With Thousand Separator
BigDecimal bd = new BigDecimal(number);
NumberFormat formatter = NumberFormat.getInstance(Locale.US);
return formatter.format(bd.longValue());