Here you can find the source of formatDouble(double v, int decimalPlaces)
public static String formatDouble(double v, int decimalPlaces)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatDouble(double v, int decimalPlaces) { String ret = String.valueOf(v); int i = ret.indexOf("."); if (ret.length() > i + decimalPlaces + 1) ret = ret.substring(0, i + decimalPlaces + 1); else/*from w w w .ja v a 2s . c om*/ ret += "0000000000".substring(0, i + decimalPlaces + 1 - ret.length()); return ret; } }