Here you can find the source of formatNumber(double paramDouble, int paramInt)
public static String formatNumber(double paramDouble, int paramInt)
//package com.java2s; import java.math.BigDecimal; import java.text.NumberFormat; public class Main { public static String formatNumber(double paramDouble, int paramInt) { return NumberFormat.getNumberInstance().format(round(paramDouble, paramInt)); }/*from ww w . jav a 2 s. co m*/ public static double round(double paramDouble, int paramInt) { if (paramInt < 0) { throw new RuntimeException("The scale must be a positive integer or zero"); } BigDecimal localBigDecimal1 = new BigDecimal(Double.toString(paramDouble)); BigDecimal localBigDecimal2 = new BigDecimal("1"); return localBigDecimal1.divide(localBigDecimal2, paramInt, 4).doubleValue(); } }