Java Number Format Pattern format(Number value)

Here you can find the source of format(Number value)

Description

format

License

Open Source License

Declaration

public static String format(Number value) 

Method Source Code


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

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;

public class Main {
    public static final String DEFAULT_PATTERN = "'$'#,##0.00";

    public static String format(Number value) {
        return format(value, DEFAULT_PATTERN);
    }//from   ww  w  .j  a v  a  2 s  . com

    public static String format(Number value, String pattern) {
        return value != null
                ? new DecimalFormat(pattern).format(new BigDecimal(BigInteger.valueOf(value.longValue()), 2))
                : null;
    }
}

Related

  1. format(final long value, final long divider, final String unit)
  2. format(Integer num)
  3. format(long bytes)
  4. format(long value)
  5. format(Number value)
  6. format(Object num, int dev, String valueIfZero)
  7. format(Object price)
  8. format(String str_number, int digits)
  9. format(String value)