Here you can find the source of getFormattedString(double d, int numDecimalPlaces)
public static String getFormattedString(double d, int numDecimalPlaces)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { public static String getFormattedString(double d, int numDecimalPlaces) { StringBuilder sb = new StringBuilder(); sb.append("##."); for (int i = 0; i < numDecimalPlaces; i++) sb.append("#"); DecimalFormat df = new DecimalFormat(sb.toString()); return df.format(d); }// ww w. j a v a 2 s.co m }