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

StringFormatNumber(Object o, String patter)
Format Number
double d = 0;
try {
    d = Double.parseDouble(String.valueOf(o));
    DecimalFormat df = new DecimalFormat(patter);
    return df.format(d);
} catch (Exception e) {
    System.out.println(e.getMessage());
    return "";
...
StringformatoDecimalPunto(String numero)
recibe de la base de datos un decimal de la forma 00000.00 o 00000 (sin decimales)
y lo formatea de la forma 00000.00
if (!nullToBlank(numero).equals("")) {
    numero = numero.trim();
    String s = "#########.##";
    DecimalFormatSymbols dformater_rules = new DecimalFormatSymbols();
    dformater_rules.setDecimalSeparator('.');
    DecimalFormat decimalFormat = new DecimalFormat(s, dformater_rules);
    decimalFormat.setMaximumFractionDigits(2);
    decimalFormat.setMinimumFractionDigits(2);
...
StringformatQuantity(Long quantity)
Formats an Long representing a quantity into a string
if (quantity == null)
    return "";
else
    return formatQuantity(quantity.doubleValue());
StringformattedDuration(long pStartTime)
formatted Duration
DecimalFormat df = new DecimalFormat("#,###,###,##0.000");
return df.format((System.currentTimeMillis() - pStartTime) / 1000.00);
StringformatThousands(String inValue)
format Thousands
String value = inValue;
try {
    value = DF_THOUSANDS.format(Long.parseLong(value));
} catch (NumberFormatException nfe) {
return value;
StringformatTime(long endTime, long startTime)
format Time
long milliseconds = endTime - startTime;
return formatTime(milliseconds);
StringformatTokens(long tokens)
format Tokens
return format.format(tokens);
StringformatValue(int value)
format Value
return new DecimalFormat("#, ###").format(value);
StringformatValue(Object value)
format Value
if (value == null) {
    return "0";
if (value instanceof Long) {
    return String.valueOf((Long) value);
} else if (value instanceof Double) {
    return formatSimpleDouble((Double) value);
} else {
...
doubleformatWith6Digits(String input)
format With Digits
DecimalFormat df = new DecimalFormat("###.000000");
double input_double = Double.parseDouble(input);
String result = df.format(input_double);
double result_double = Double.parseDouble(result);
return result_double;