Here you can find the source of format(BigDecimal num)
public static String format(BigDecimal num)
//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); } }