Here you can find the source of formatDouble(double val)
public static String formatDouble(double val)
//package com.java2s; //License from project: Apache License public class Main { public static String formatDouble(double val) { String num = String.format("%.2f", val); if (!num.startsWith("-")) { return pad(" " + num, 6); } else {//www.java2 s . com return pad(num, 6); } } public static String pad(String text, int totalLength) { StringBuffer sb = new StringBuffer(text); while (sb.length() < totalLength) { sb.append(" "); } return sb.toString(); } }