Java Float to String floatToString(float val, int width)

Here you can find the source of floatToString(float val, int width)

Description

float To String

License

Open Source License

Declaration

public static String floatToString(float val, int width) 

Method Source Code


//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;
    }
}

Related

  1. floatToString(float f, boolean asAPI)
  2. floatToString(float f, int precision)
  3. floatToString(float f, int precision)
  4. floatToString(float fValue)
  5. floatToString(Float num)
  6. FloatToString(float value)
  7. floatToString(float value)
  8. floatToString(float value, int precision)
  9. floatToString(float value, String format)