Java Double to String doubleToString(final Double value)

Here you can find the source of doubleToString(final Double value)

Description

For Visual Studio compatibility: converts a Double-type to a String, but ensures that whole numbers have no decimal point.

License

Open Source License

Parameter

Parameter Description
value A Double to convert to a String

Return

A String representation of a Double

Declaration

public static String doubleToString(final Double value) 

Method Source Code

//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

public class Main {
    /**/*from  ww w  .  j a  va  2s .com*/
     * For Visual Studio compatibility: converts a Double-type to a String, but
     * ensures that whole numbers have no decimal point.
     *
     * This is for rule engine parsing and display. Ie, when we have a double
     * value "0", we display it as "0.0", while .NET (and C# in general)
     * displays "0". This leads to interop headaches, particularly with
     * ALLOWEDVALUES fields.
     *
     * @param value
     *        A Double to convert to a String
     * @return A String representation of a Double
     */
    public static String doubleToString(final Double value) {
        if (value == null) {
            return null;
        }

        if (value.intValue() == value.doubleValue()) {
            return Integer.toString(value.intValue());
        }

        return value.toString();
    }
}

Related

  1. doubleToString(double value, int afterDecimalPoint)
  2. doubleToString(double value, int afterDecimalPoint)
  3. doubleToString(double[] values)
  4. doubleToString(final double d)
  5. doubleToString(final double v, final int roundingDigits)
  6. doubleToString(final Double value)
  7. doubleToString(final double value, final boolean stripDotZero)
  8. doubleToString4(double value)
  9. doubleToStringWithMinimumPrecision(double d)