Java Number Format Pattern format(Object num, int dev, String valueIfZero)

Here you can find the source of format(Object num, int dev, String valueIfZero)

Description

format

License

Apache License

Declaration

public static String format(Object num, int dev, String valueIfZero) 

Method Source Code


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

import java.text.DecimalFormat;

public class Main {

    public static String format(Object num, int dev, String valueIfZero) {
        if (num == null) {
            return valueIfZero;
        }/*from   w w w .  j a  v  a 2 s .c  om*/
        if (dev == 0) {
            dev = 1;
        }
        double f = Double.parseDouble(num.toString());
        f = f / dev;

        if (f < 0.01) {
            return valueIfZero;
        }
        DecimalFormat df1 = new DecimalFormat("##########0.00");
        return df1.format(f);
    }
}

Related

  1. format(Integer num)
  2. format(long bytes)
  3. format(long value)
  4. format(Number value)
  5. format(Number value)
  6. format(Object price)
  7. format(String str_number, int digits)
  8. format(String value)
  9. formatAmtByComma(String amt, int len)