Java Number Format Pattern objectToString(Object obj, DecimalFormat fmt)

Here you can find the source of objectToString(Object obj, DecimalFormat fmt)

Description

object To String

License

Apache License

Declaration

public static final String objectToString(Object obj, DecimalFormat fmt) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.DecimalFormat;

public class Main {
    public static final String objectToString(Object obj, DecimalFormat fmt) {
        fmt.setDecimalSeparatorAlwaysShown(false);
        if (obj instanceof Double)
            return fmt.format(((Double) obj).doubleValue());
        if (obj instanceof Long)
            return fmt.format(((Long) obj).longValue());
        else//from w  ww  .  j  a va  2 s. c o m
            return obj.toString();
    }
}

Related

  1. getZeroDecimalFormat()
  2. isDecimalFormat(DecimalFormat decimalFormat)
  3. isDecimalFormatValid(final String pattern)
  4. matchOptionalFormatting(Number number, String formatting, StringBuffer outputTo)
  5. normalizeNumberFormat(NumberFormat numberFormat, int scale, int precision)
  6. print(float[] array, NumberFormat nf)
  7. resetDecimalFormat()
  8. resetDecimalFormatByLocale(Locale locale)
  9. roundNumber(Number number, DecimalFormat format)