Java BigDecimal Format format(BigDecimal num)

Here you can find the source of format(BigDecimal num)

Description

format

License

Open Source License

Declaration

public static String format(BigDecimal num) 

Method Source Code


//package com.java2s;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    public static String format(Double num) {
        java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
        return df.format(num);
    }/* w w w.  j ava 2s . co m*/

    public static String format(BigDecimal num) {
        java.text.DecimalFormat df = new java.text.DecimalFormat("0.00");
        return df.format(num);
    }

    public static String format(BigDecimal num, int divisor) {
        return format(num.divide(new BigDecimal(divisor)));
    }

    public static String format(String num, int scale, boolean isFix) {

        NumberFormat nf = new DecimalFormat(parse(num, scale, isFix).toString());

        return nf.format(new BigDecimal(num));
    }

    public static BigDecimal parse(String num, int scale, boolean isFix) {
        StringBuffer flag = new StringBuffer();
        flag.append("#");

        for (int i = 0; i < scale; i++) {
            if (i == 0) {
                flag.append(isFix ? ".0" : ".#");
            } else {
                flag.append(isFix ? "0" : "#");
            }
        }

        return new BigDecimal(num);
    }
}

Related

  1. format(BigDecimal decData, int precision, int scale)
  2. format(BigDecimal decimal)
  3. format(BigDecimal n, int prec)
  4. format(BigDecimal n, int prec)
  5. format(BigDecimal no, String formatter)
  6. format(BigDecimal num)
  7. format(BigDecimal num)
  8. format(BigDecimal number, String format)
  9. format(final BigDecimal bd)