Java Utililty Methods Number Format Pattern

List of utility methods to do Number Format Pattern

Description

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

Method

StringgetFormatedPrice(BigDecimal price)
get Formated Price
String formatedPrice = PRICE_FORMATTER.format(price);
if (currency != null && currency.length() > 0)
    formatedPrice += " (" + currency + ")";
return formatedPrice;
StringgetFormattedInteger(int n)
Utility method to get an ineteger as a formatted string.
df.setGroupingUsed(true);
df.setGroupingSize(3);
dfs.setGroupingSeparator('.');
df.setDecimalFormatSymbols(dfs);
return df.format(n);
StringgetFormattedNumber(int number)
get Formatted Number
return formatter.format(number);
NumbergetFormattedNumber(NumberFormat numberFormat, String fieldValue, Class valueClass)
Creates a number from a string value
if (valueClass.equals(Byte.class)) {
    return new Byte((numberFormat.parse(fieldValue)).byteValue());
} else if (valueClass.equals(Integer.class)) {
    return Integer.valueOf((numberFormat.parse(fieldValue)).intValue());
} else if (valueClass.equals(Long.class)) {
    return new Long((numberFormat.parse(fieldValue)).longValue());
} else if (valueClass.equals(Short.class)) {
    return new Short((numberFormat.parse(fieldValue)).shortValue());
...
StringgetFormattedNumber(String input)
get Formatted Number
if (df == null) {
    return input;
try {
    return df.format(Double.parseDouble(input));
} catch (NumberFormatException nfe) {
    return input;
StringgetFormattedQuantity(String qty, int len, String pad)
Method getFormattedQuantity.
String result = replaceNullObjectwithBlank(qty);
char decimalseparator = java.text.DecimalFormatSymbols.getInstance().getDecimalSeparator();
char thousandseparator = java.text.DecimalFormatSymbols.getInstance().getGroupingSeparator();
if (result.equals("")) {
    result = "0";
result = result.trim();
if (result.length() > 0) {
...
StringgetFormattedString4Digits(String number, String pattern)
get Formatted String Digits
double amount = 0;
try {
    amount = Double.parseDouble(number);
    DecimalFormat formatter = new DecimalFormat(pattern);
    return formatter.format(amount);
} catch (Exception ex) {
    return number;
DecimalFormatgetFormatter()
get Formatter
return FORMATTER.get();
DecimalFormatgetFormatter()
get Formatter
if (formatter == null) {
    DecimalFormat lFormatter = new DecimalFormat("#,###.###");
    DecimalFormatSymbols smb = new DecimalFormatSymbols();
    smb.setGroupingSeparator(' ');
    lFormatter.setDecimalFormatSymbols(smb);
    formatter = lFormatter;
return formatter;
...
DecimalFormatgetFormatter(int precision)
get Formatter
String cacheFormat = cache.get(Integer.valueOf(precision));
if (cacheFormat != null)
    return new DecimalFormat(cacheFormat);
StringBuilder format = new StringBuilder("##0.");
for (int i = 0; i < precision; i++)
    format.append(0);
DecimalFormat df = new DecimalFormat(format.toString());
cache.put(Integer.valueOf(precision), format.toString());
...