Java Utililty Methods Double to String

List of utility methods to do Double to String

Description

The list of methods to do Double to String are organized into topic(s).

Method

StringdoubleToString(final double d)
Returns the double as a String, without a decimal point if the double actually stores an integer
final int i = (int) d;
return i == d ? String.valueOf(i) : String.valueOf(d);
StringdoubleToString(final double v, final int roundingDigits)
Rounds by dropping roundingDigits of double precision (similar to 'hidden precision digits' on calculators), and formats to String.
final double absv = Math.abs(v);
final String str = roundingDigits == FLOAT_PRECISION ? Float.toString((float) absv) : Double.toString(absv);
StringBuffer buf = new StringBuffer(str);
int roundingStart = (roundingDigits <= 0 || roundingDigits > 13) ? 17 : (16 - roundingDigits);
int ePos = str.lastIndexOf('E');
int exp = (ePos != -1) ? Integer.parseInt(str.substring(ePos + 1)) : 0;
if (ePos != -1) {
    buf.setLength(ePos);
...
StringdoubleToString(final Double value)
Converts a double into an SVG decimal string.
final int intValue = value.intValue();
if (approximatelyEqual(intValue, value)) {
    return Integer.toString(intValue);
return value.toString();
StringdoubleToString(final Double value)
For Visual Studio compatibility: converts a Double-type to a String, but ensures that whole numbers have no decimal point.
if (value == null) {
    return null;
if (value.intValue() == value.doubleValue()) {
    return Integer.toString(value.intValue());
return value.toString();
StringdoubleToString(final double value, final boolean stripDotZero)
Converts a given double value to a String with a single digit after that decimal point and optionally strips ".0" if present.
return fixedPointToString((long) (value * 10), stripDotZero);
StringdoubleToString4(double value)
double To String
if (Double.isNaN(value)) {
    return " --- ";
return String.format("%.4f", value);
StringdoubleToStringWithMinimumPrecision(double d)
double To String With Minimum Precision
return d == (int) d ? String.format("%d", (int) d) : String.format("%s", d);