Here you can find the source of formatNumberByMaxFrac(BigDecimal number, int val)
public static String formatNumberByMaxFrac(BigDecimal number, int val)
//package com.java2s; import java.math.BigDecimal; import java.text.NumberFormat; public class Main { public static String formatNumberByMaxFrac(double number, int val) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(val); nf.setGroupingUsed(false);/* w w w . ja va2 s . c o m*/ return nf.format(number); } public static String formatNumberByMaxFrac(BigDecimal number, int val) { if (number == null) return ""; NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(val); return nf.format(number); } }