Java Utililty Methods Float Number Format

List of utility methods to do Float Number Format

Description

The list of methods to do Float Number Format are organized into topic(s).

Method

StringformatFloat(double num)
format Float
StringBuffer text = new StringBuffer(Double.toString(num));
int index = text.toString().indexOf(".");
if (index < 0) {
    text.append(".");
    index = text.toString().indexOf(".");
text.append("00");
text.delete(index + 3, text.length());
...
StringformatFloat(double number, int precision)
Returns the specified double, formatted as a string, to n decimal places, as specified by precision.
String text = Double.toString(number);
if (precision >= text.length()) {
    return text;
int start = text.indexOf(".") + 1;
if (start == 0)
    return text;
if (precision == 0)
...
StringformatFloat(double value, int decimals)
format Float
String fmt = "%5." + String.valueOf(decimals) + "f";
return String.format(fmt, value);
StringformatFloat(float f)
format Float
if (f == (int) f)
    return String.format("%d", (int) f);
else
    return String.format("%s", f);
floatformatFloat(float input, int numDecimals)
format Float
float m = (float) Math.pow(10, numDecimals);
return Math.round(input * m) / m;
StringformatFloat(float num, int width, int precision)
format Float
return formatReal(String.valueOf(num), width, precision);
StringformatFloat(float val)
format Float
String retval = Float.toString(val);
return (retval);
FloatformatFloat(String value)
Checks if the value can safely be converted to a float primitive.
if (value == null) {
    return null;
try {
    return new Float(value);
} catch (NumberFormatException e) {
    return null;