Here you can find the source of doubleToAtLeastString(double d, int length)
Parameter | Description |
---|---|
d | a parameter |
length | a parameter |
public static String doubleToAtLeastString(double d, int length)
//package com.java2s; //GNU General Public License (GPL). import java.text.DecimalFormat; import java.text.NumberFormat; public class Main { /**// w w w. j a v a2 s. c om * 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; } }