Java Number Format Pattern formatNumber(Number num)

Here you can find the source of formatNumber(Number num)

Description

format Number

License

Open Source License

Declaration

public static String formatNumber(Number num) 

Method Source Code

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

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
    private static final String DEFAULT_NUMBER_FORMAT = "0.####";

    public static String formatNumber(Number num, String pattern) {
        return num == null ? null : getDecimalFormat(pattern).format(num);
    }// w w w . j a v a2 s . c  o  m

    public static String formatNumber(Number num) {
        return formatNumber(num, DEFAULT_NUMBER_FORMAT);
    }

    public static DecimalFormat getDecimalFormat(String pattern) {
        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        symbols.setDecimalSeparator('.');
        DecimalFormat format = new DecimalFormat(pattern);
        format.setDecimalFormatSymbols(symbols);
        return format;
    }
}

Related

  1. formatNumber(final long number)
  2. formatNumber(int num)
  3. formatNumber(int source)
  4. formatNumber(long number)
  5. formatNumber(long number)
  6. formatNumber(Number number)
  7. FormatNumber(Object o,String patter)
  8. formatoDecimalPunto(String numero)
  9. formatQuantity(Long quantity)