Here you can find the source of floatToString(float val, int width)
public static String floatToString(float val, int width)
//package com.java2s; //License from project: Open Source License import java.text.DecimalFormat; public class Main { static DecimalFormat mDF = new DecimalFormat("0.0000"); static String mSpaces = " "; public static String floatToString(float val, int width) { String str = mDF.format(val); if (str.length() >= width) { return str; }/*from w w w . ja v a2s .c om*/ return mSpaces.substring(0, width - str.length()) + str; } }