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

StringgetStrFormatTwoPoint(float param)
get Str Format Two Point
param += 0.001;
java.text.DecimalFormat df = new java.text.DecimalFormat("#0.00");
return df.format(param);
NumberFormatgetTeamIDFormat()
get Team ID Format
NumberFormat format = NumberFormat.getIntegerInstance();
format.setMinimumIntegerDigits(1);
format.setMaximumIntegerDigits(4);
format.setGroupingUsed(false);
format.setParseIntegerOnly(true);
return format;
NumberFormatgetUiNumberFormat()
Creates a uniform number format which is similar to that of eg.
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat format = new DecimalFormat("###.##", symbols);
format.setGroupingUsed(false);
format.setMaximumFractionDigits(Integer.MAX_VALUE);
return format;
NumberFormatgetUSNumberFormatter()
get US Number Formatter
NumberFormat nf = NumberFormat.getInstance(Locale.US);
return setFloatDigits(nf);
StringgetValueFormatted(String name, String value)
Get metric value formatted as String
String formattedValue;
value = value.replace(",", ".");
if (value.equals("-")) {
    return value;
if (value.equals("NaN")) {
    return "---";
if ((((Math.abs(Double.parseDouble(value) * 1000) < 1.0))
        && ((Math.abs(Double.parseDouble(value) * 1000) > 0.0)))
        || (Math.abs(Double.parseDouble(value) / 1000.0) > 10)) {
    NumberFormat formatter = new DecimalFormat("0.###E0");
    formattedValue = formatter.format(Double.parseDouble(value));
else if ((name.toLowerCase().equals("attributes")) || (name.toLowerCase().equals("bound"))
        || (name.toLowerCase().equals("distinct labelsets")) || (name.toLowerCase().equals("instances"))
        || (name.toLowerCase().equals("labels x instances x features"))
        || (name.toLowerCase().equals("labels"))
        || (name.toLowerCase().equals("number of binary attributes"))
        || (name.toLowerCase().equals("number of labelsets up to 2 examples"))
        || (name.toLowerCase().equals("number of labelsets up to 5 examples"))
        || (name.toLowerCase().equals("number of labelsets up to 10 examples"))
        || (name.toLowerCase().equals("number of labelsets up to 50 examples"))
        || (name.toLowerCase().equals("number of nominal attributes"))
        || (name.toLowerCase().equals("number of numeric attributes"))
        || (name.toLowerCase().equals("number of unique labelsets")) || (name.toLowerCase()
                .equals("number of unconditionally dependent label pairs by chi-square test"))) {
    NumberFormat formatter = new DecimalFormat("#0");
    formattedValue = formatter.format(Double.parseDouble(value));
else {
    NumberFormat formatter = new DecimalFormat("#0.000");
    formattedValue = formatter.format(Double.parseDouble(value));
formattedValue = formattedValue.replace(",", ".");
return formattedValue;
NumberFormatgetValueFormatter()
get Value Formatter
if (_formatter == null) {
    _formatter = NumberFormat.getInstance();
    _formatter.setGroupingUsed(false);
    _formatter.setMaximumFractionDigits(3);
return _formatter;
DecimalFormatgetZeroDecimalFormat()
get Zero Decimal Format
return new DecimalFormat("0.0000");
booleanisDecimalFormat(DecimalFormat decimalFormat)
is Decimal Format
String pattern = decimalFormat.toPattern();
StringBuffer buf = new StringBuffer(pattern);
DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols();
char[] charList = new char[4];
charList[0] = dfs.getZeroDigit();
charList[1] = dfs.getDigit();
charList[2] = dfs.getDecimalSeparator();
charList[3] = dfs.getGroupingSeparator();
...
booleanisDecimalFormatValid(final String pattern)
Validates a DecimalFormat decimal format .
boolean result = false;
try {
    new DecimalFormat(pattern);
    result = true; 
} catch (Throwable e) {
return result;
intmatchOptionalFormatting(Number number, String formatting, StringBuffer outputTo)
match Optional Formatting
NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
if ((0 < formatting.length()) && Character.isDigit(formatting.charAt(0))) {
    numberFormat.setMinimumIntegerDigits(Integer.parseInt(formatting.charAt(0) + ""));
    if ((2 < formatting.length()) && (formatting.charAt(1) == '.')
            && Character.isDigit(formatting.charAt(2))) {
        numberFormat.setMaximumFractionDigits(Integer.parseInt(formatting.charAt(2) + ""));
        numberFormat.format(number, outputTo, new FieldPosition(0));
        return 3;
...