Here you can find the source of formatNumber(Double val, int numDec, int width)
public static String formatNumber(Double val, int numDec, int width)
//package com.java2s; //License from project: LGPL public class Main { public static final String UNKNOWN_VALUE = "-"; public static String formatNumber(Double val, int numDec, int width) { if (val == null) { return String.format("%" + width + "s", UNKNOWN_VALUE); } else {//from w w w . j av a2s.c o m return String.format("%" + width + "." + numDec + "f", val); } } }