Here you can find the source of formatNum(double num, int numfracdigits)
public static String formatNum(double num, int numfracdigits)
//package com.java2s; //License from project: Open Source License import java.text.NumberFormat; public class Main { public static NumberFormat numberFormat = null; public static String formatNum(double num, int numfracdigits) { if (numberFormat == null) { // Cache the number format so that we don't have to get // info about local language etc. from the OS each time. numberFormat = NumberFormat.getInstance(); // force to not include commas because we want the strings // to be parsable back into numeric values. - DRG numberFormat.setGroupingUsed(false); }//from w ww . j a v a 2 s . c om numberFormat.setMinimumFractionDigits(numfracdigits); numberFormat.setMaximumFractionDigits(numfracdigits); return numberFormat.format(num); } }