Java Number Format Pattern formatValue(Object value)

Here you can find the source of formatValue(Object value)

Description

format Value

License

Open Source License

Declaration

public static String formatValue(Object value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String formatValue(Object value) {
        if (value == null) {
            return "0";
        }// w  w w  .  j  av a 2s.c om

        if (value instanceof Long) {
            return String.valueOf((Long) value);
        } else if (value instanceof Double) {
            return formatSimpleDouble((Double) value);
        } else {
            return String.valueOf(value);
        }
    }

    public static String formatSimpleDouble(Double value) {
        try {
            java.text.DecimalFormat form = new java.text.DecimalFormat(
                    "##0.000");
            String s = form.format(value);
            return s;
        } catch (Exception e) {
            return "0.000";
        }

    }
}

Related

  1. formattedDuration(long pStartTime)
  2. formatThousands(String inValue)
  3. formatTime(long endTime, long startTime)
  4. formatTokens(long tokens)
  5. formatValue(int value)
  6. formatWith6Digits(String input)
  7. getBigDecimalFromString(String numericValue, String numberFormat)
  8. getDataFormat(final boolean grouped, final boolean isFloat, int declen)
  9. getDefaultDecimalFormat()