Java Double to String doubleToString(final Double value)

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

Description

Converts a double into an SVG decimal string.

License

Open Source License

Parameter

Parameter Description
value a double value

Return

an SVG number string

Declaration

public static final String doubleToString(final Double value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w w  w . ja v  a  2s  . co  m
     * Converts a double into an SVG decimal string.
     *
     * @param value a double value
     *
     * @return an SVG number string
     */
    public static final String doubleToString(final Double value) {
        final int intValue = value.intValue();
        if (approximatelyEqual(intValue, value)) {
            return Integer.toString(intValue);
        }
        return value.toString();
    }

    /**
     * Returns true if a and b are approximately equal.
     *
     * @param a a double
     * @param b a double
     *
     * @return true if a and b are approximately equal
     */
    public static final boolean approximatelyEqual(final double a, final double b) {
        return Math.abs(a - b) < 0.000001;
    }
}

Related

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