Java Number Format numberFormat(String pattern, BigDecimal number)

Here you can find the source of numberFormat(String pattern, BigDecimal number)

Description

number Format

License

LGPL

Declaration

public static String numberFormat(String pattern, BigDecimal number) 

Method Source Code


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

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

public class Main {

    public static String numberFormat(String pattern, BigDecimal number) {
        String numberStr = null;/*  w  w  w  .j  a v a2s  .com*/
        if (number == null) {
            return "";
        }
        try {
            if (pattern == null || pattern.equals("")) {
                numberStr = new DecimalFormat("#0.00##").format(number.doubleValue());
            } else {
                numberStr = new DecimalFormat(pattern).format(number.doubleValue());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return numberStr;
    }
}

Related

  1. numberFormat(double value, String format)
  2. numberFormat(int fractionDigits, Locale locale)
  3. numberFormat(int i)
  4. numberFormat(int num)
  5. numberFormat(Number number, String... pattern)
  6. numberFormat(String pattern, double value)
  7. numberFormate(double num)
  8. numberFormatHelper(String string, double d)
  9. numberFormatter(String pattern, int maxDigits)