Here you can find the source of formatBigDecimal(BigDecimal number, int val)
public static String formatBigDecimal(BigDecimal number, int val)
//package com.java2s; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.DecimalFormat; public class Main { public static String formatBigDecimal(BigDecimal number, int val, boolean isForceMax) { DecimalFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(val); if (isForceMax) nf.setMinimumFractionDigits(val); nf.setRoundingMode(RoundingMode.HALF_UP); nf.setGroupingUsed(false);/*from www.j a v a 2s . c om*/ return nf.format(number); } public static String formatBigDecimal(BigDecimal number, int val) { DecimalFormat nf = new DecimalFormat(); nf.setMaximumFractionDigits(val); nf.setMinimumFractionDigits(val); nf.setRoundingMode(RoundingMode.HALF_UP); nf.setGroupingUsed(true); return nf.format(number); } }