Java Number Format numberFormat(Number number, String... pattern)

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

Description

number Format

License

Apache License

Declaration

public static String numberFormat(Number number, String... pattern) 

Method Source Code


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

import java.io.*;
import java.text.DecimalFormat;
import java.text.Format;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
    private static Format FORMAT = new DecimalFormat("#.##");

    public static String numberFormat(Number number, String... pattern) {
        return isNull((Object[]) pattern) ? FORMAT.format(number) : FORMAT.format(pattern[0]);
    }//from  w  w  w  .  ja v a  2 s.  c  o m

    public static boolean isNull(Object o) {
        return null == o;
    }

    public static boolean isNull(List<?> list) {
        return null == list || list.size() == 0;
    }

    public static boolean isNull(Set<?> set) {
        return null == set || set.size() == 0;
    }

    public static boolean isNull(Map<?, ?> map) {
        return null == map || map.size() == 0;
    }

    public static boolean isNull(Long lg) {
        return null == lg || lg.longValue() == 0L;
    }

    public static boolean isNull(Integer it) {
        return null == it || it.intValue() == 0;
    }

    public static boolean isNull(File file) {
        return null == file || !file.exists();
    }

    public static boolean isNull(Object[] strs) {
        return null == strs || strs.length == 0;
    }
}

Related

  1. NumberFormat(double str, int max, int min)
  2. numberFormat(double value, String format)
  3. numberFormat(int fractionDigits, Locale locale)
  4. numberFormat(int i)
  5. numberFormat(int num)
  6. numberFormat(String pattern, BigDecimal number)
  7. numberFormat(String pattern, double value)
  8. numberFormate(double num)
  9. numberFormatHelper(String string, double d)