The list of methods to do Float to String are organized into topic(s).
String
floatToFormattedString(float f) Shortens numbers to a representable state (#*.###)
if (f == (int) f) {
return String.valueOf((int) f);
} else {
return new DecimalFormat("#.##").format(f);
String
floatToString(float d) float To String
if (d == (long) d)
return String.format("%d", (long) d);
else {
d = Math.round(d * 100);
d = d / 100;
String s = String.valueOf(d);
return s.contains(".") ? s.replaceAll("0*$", "").replaceAll("\\.$", "") : s;
String
floatToString(float f, boolean asAPI) Converts a
float to a string and is removing the ".0" if the float is an integer.
String valS = String.valueOf(f);
return valS.endsWith(".0") ? valS.substring(0, valS.length() - 2) : (valS + (asAPI ? "f" : ""));
String
floatToString(float f, int precision) float To String
boolean negative = f < 0;
f = (negative ? -f : f);
long whole_rep = Math.round(f * Math.pow(10, -precision));
String wholeRepStr = String.valueOf(whole_rep);
if (whole_rep == 0)
return wholeRepStr;
int whole_len = wholeRepStr.length();
int pre_len = whole_len + precision;
...
String
floatToString(float f, int precision) Convert float to string, with given precision.
String s = Float.toString(f);
int i = s.lastIndexOf('.');
if (i == -1)
return s;
int end = i + precision + 1;
return (end < s.length()) ? s.substring(0, end) : s;
String
floatToString(float fValue) Converts a float value to a String value
String value = String.valueOf(fValue);
value = value.replaceFirst("\\.*0*$", "");
return value;
String
floatToString(Float num) float To String
java.text.NumberFormat f = java.text.NumberFormat.getInstance();
f.setGroupingUsed(false);
return f.format(num);
String
floatToString(float val, int width) float To String
String str = mDF.format(val);
if (str.length() >= width) {
return str;
return mSpaces.substring(0, width - str.length()) + str;