Here you can find the source of doubleToFixedString(double d, int length)
public static String doubleToFixedString(double d, int length)
//package com.java2s; //GNU General Public License (GPL). import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { public static String doubleToFixedString(double d, int length) { String s = doubleToAtLeastString(d, length); if (s.charAt(0) != '-') { return " " + s.substring(0, length - 1); }/* w w w .ja v a2 s . com*/ return s.substring(0, length); } /** * return a string that is at least a certain * number of characters in length. This is helpful * when populating text boxes with number data that * may otherwise be short and packed too tightly * by the GUI components. * @param d * @param length * @return */ public static String doubleToAtLeastString(double d, int length) { //String s = String.valueOf(d); NumberFormat formatter = new DecimalFormat("0.000"); String s = formatter.format(d); for (int i = s.length(); i < length; i++) { s += "0"; } return s; } }