Here you can find the source of formatDouble(double d, int n, String pad)
public static String formatDouble(double d, int n, String pad)
//package com.java2s; /**//from ww w. java 2 s . co m * This class was written by Stephen Crane (jscrane@gmail.com) * and is released under the terms of the GNU GPL * (http://www.gnu.org/licenses/gpl.html). */ public class Main { public static String formatDouble(double d, int n, String pad) { String s = Double.toString(d); int len = s.length(); if (len > n) return s.substring(0, n); for (; len < n; len++) s = s + pad; return s; } }