Java Date Format ISO format(BigDecimal num, int divisor)

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

Description

format

License

Open Source License

Declaration

public static String format(BigDecimal num, int divisor) 

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);
    }//from   w  w w. j a va2s.  c o 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. createISODateTimeFormatter()
  2. formatAlternativeIso8601Date(Date date)
  3. formatAsIso8601Timestamp(Date date)
  4. formatAwsFlavouredISO8601Date(Date date)
  5. formatDateAsIsoDate(Calendar calendar)