Here you can find the source of formatNumber(int fractionDigits, double value)
public static String formatNumber(int fractionDigits, double value)
//package com.java2s; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; public class Main { static List<NumberFormat> nfs = new ArrayList<NumberFormat>(); public static String formatNumber(int fractionDigits, double value) { if (fractionDigits >= 0 && fractionDigits <= 10) { return nfs.get(fractionDigits).format(value); }// w w w .j a v a 2 s.c om throw new RuntimeException("Only supports fraction digits between 0 to 10"); } }