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

StringtoDecimalFormat(BigDecimal value)
to Decimal Format
return value != null ? DECIMAL_FORMAT.format(value) : "$0.00";
StringtoFormattedNumber(Object value)
to Formatted Number
if (value == null) {
    return "";
if (value instanceof Double || value instanceof Float) {
    return DEFAULT_DECIMAL_FORMATTER.format(value);
return value.toString();
NumbertoNumber(String numString, String numFormatPattern)
Converts a String to a Number, using the specified pattern.
Number number = null;
if (numFormatPattern == null) {
    numFormatPattern = "######.##";
synchronized (numberFormat) {
    numberFormat.applyPattern(numFormatPattern);
    number = numberFormat.parse(numString);
return number;
StringtoNumberFormat(String input)
to Number Format
if (input.indexOf(".") != -1)
    return NumberFormat.getInstance().format((new java.lang.Double(input)).doubleValue());
else {
    return NumberFormat.getInstance().format((new java.lang.Long(input)).longValue());
StringtoString(int[] a, String separator, NumberFormat formatter)
to String
StringBuffer result = new StringBuffer();
if (formatter != null) {
    if (a.length > 0)
        result.append(formatter.format(a[0]));
    for (int i = 1; i < a.length; i++)
        result.append(separator).append(formatter.format(a[i]));
} else {
    if (a.length > 0)
...
StringtoStringFormatted(byte[] bytes)
Format a byte array with a numbered header.
StringBuilder sb = new StringBuilder();
DecimalFormat df = new DecimalFormat("00 | ");
if (bytes != null) {
    int len = bytes.length;
    for (int i = 0; i < bytes.length; i++) {
        sb.append("-----");
    sb.append("\n|");
...
doubleunformatAmount(String formattedNumber)
unformats a formatted number to be a double again
NumberFormat numberFormatter = NumberFormat.getCurrencyInstance();
Number number = null;
try {
    number = numberFormatter.parse(formattedNumber);
} catch (ParseException e) {
    e.printStackTrace();
double unformattedNumber = number.doubleValue();
...
BigDecimalunformatingDecimalNumber(String cadena, Locale locale, int maxIntPart, int maxFloatPart)
Translate an String to BigDecimal number.
BigDecimal result = null;
NumberFormat numberFormat = settingUpValuesOfFormat(locale, maxIntPart, maxFloatPart);
if (null != cadena && !"".equals(cadena.trim())) {
    try {
        Number number = numberFormat.parse(cadena);
        result = new BigDecimal(Double.toString(number.doubleValue()));
    } catch (ParseException e) {
return result;