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

StringcountFormat(int no)
Returns a formatted number inclusive counting ending (see #countEnding(int) .
return new DecimalFormat().format(no) + countEnding(no);
DecimalFormatcreateDecimalFormat(final String pattern)
Creates a new DecimalFormat using comming dot as a separator so local decimal serparators dont matter
return createDecimalFormat(pattern, '.');
DecimalFormatCreateDecimalFormat(int numberOfDecimalsDisplayed)
Gets the amount of decimals that should be displayed with a DecimalFormat object.
if (numberOfDecimalsDisplayed < 1)
    return new DecimalFormat("#");
String format = "#.";
for (int i = 1; i <= numberOfDecimalsDisplayed; i++)
    format += "#";
return new DecimalFormat(format);
DecimalFormatcreateDecimalFormat(String pattern)
create Decimal Format
return new DecimalFormat(pattern);
DecimalFormatcreateDecimalFormatter(String pattern)
create Decimal Formatter
DecimalFormat formatter = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
formatter.applyPattern(pattern);
return formatter;
NumberFormatcreateNumberFormat()
create Number Format
DecimalFormat result = new DecimalFormat();
result.setMaximumFractionDigits(4);
return result;
NumberFormatcreateNumberFormat(int cnt)
create Number Format
StringBuilder sb = new StringBuilder();
sb.append("0");
if (cnt > 0) {
    sb.append(".");
    for (int i = 0; i < cnt; i++) {
        sb.append("0");
return new DecimalFormat(new String(sb));
NumberFormatcreateOrderVolumeNumberFormat()
create Order Volume Number Format
return new DecimalFormat("###,###,###,###,##0.00");
NumberFormatcreateRealFormat()
create Real Format
NumberFormat format = NumberFormat.getNumberInstance();
format.setMinimumFractionDigits(0);
format.setMaximumFractionDigits(14);
return format;
StringexpFormatRupiah(Number input, boolean prependRp)
exp Format Rupiah
if (rupiahFormat == null) {
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
    decimalFormatSymbols.setCurrencySymbol(prependRp ? "Rp " : "");
    decimalFormatSymbols.setMonetaryDecimalSeparator(',');
    decimalFormatSymbols.setGroupingSeparator('.');
    rupiahFormat = (DecimalFormat) NumberFormat.getCurrencyInstance();
    rupiahFormat.setDecimalFormatSymbols(decimalFormatSymbols);
return rupiahFormat.format(input);