public final class

Double

extends Number
implements Comparable<T>
java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Double

Class Overview

The wrapper for the primitive type double.

See Also

Summary

Constants
int MAX_EXPONENT Maximum exponent that a finite value of the double type may have.
double MAX_VALUE Constant for the maximum double value, (2 - 2-52) * 21023.
int MIN_EXPONENT Minimum exponent that a normal value of the double type may have.
double MIN_NORMAL Constant for the smallest positive normal value of the double type.
double MIN_VALUE Constant for the minimum double value, 2-1074.
double NEGATIVE_INFINITY Constant for the negative infinity value of the double type.
double NaN Constant for the Not-a-Number (NaN) value of the double type.
double POSITIVE_INFINITY Constant for the positive infinity value of the double type.
int SIZE Constant for the number of bits needed to represent a double in two's complement form.
Fields
public static final Class<Double> TYPE The Class object that represents the primitive type double.
Public Constructors
Double(double value)
Constructs a new Double with the specified primitive double value.
Double(String string)
Constructs a new Double from the specified string.
Public Methods
byte byteValue()
Returns this object's value as a byte.
static int compare(double double1, double double2)
Compares the two specified double values.
int compareTo(Double object)
Compares this object to the specified double object to determine their relative order.
static long doubleToLongBits(double value)
Converts the specified double value to a binary representation conforming to the IEEE 754 floating-point double precision bit layout.
static long doubleToRawLongBits(double value)
Converts the specified double value to a binary representation conforming to the IEEE 754 floating-point double precision bit layout.
double doubleValue()
Gets the primitive value of this double.
boolean equals(Object object)
Tests this double for equality with object.
float floatValue()
Returns this object's value as a float.
int hashCode()
Returns an integer hash code for this object.
int intValue()
Returns this object's value as an int.
static boolean isInfinite(double d)
Indicates whether the specified double represents an infinite value.
boolean isInfinite()
Indicates whether this object represents an infinite value.
boolean isNaN()
Indicates whether this object is a Not-a-Number (NaN) value.
static boolean isNaN(double d)
Indicates whether the specified double is a Not-a-Number (NaN) value.
static double longBitsToDouble(long bits)
Converts the specified IEEE 754 floating-point double precision bit pattern to a Java double value.
long longValue()
Returns this object's value as a long.
static double parseDouble(String string)
Parses the specified string as a double value.
short shortValue()
Returns this object's value as a short.
static String toHexString(double d)
Converts the specified double into its hexadecimal string representation.
static String toString(double d)
Returns a string containing a concise, human-readable description of the specified double value.
String toString()
Returns a string containing a concise, human-readable description of this object.
static Double valueOf(String string)
Parses the specified string as a double value.
static Double valueOf(double d)
Returns a Double instance for the specified double value.
[Expand]
Inherited Methods
From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

public static final int MAX_EXPONENT

Since: API Level 9

Maximum exponent that a finite value of the double type may have. Equal to Math.getExponent(Double.MAX_VALUE).

Constant Value: 1023 (0x000003ff)

public static final double MAX_VALUE

Since: API Level 1

Constant for the maximum double value, (2 - 2-52) * 21023.

Constant Value: 1.7976931348623157E308

public static final int MIN_EXPONENT

Since: API Level 9

Minimum exponent that a normal value of the double type may have. Equal to Math.getExponent(Double.MIN_NORMAL).

Constant Value: -1022 (0xfffffc02)

public static final double MIN_NORMAL

Since: API Level 9

Constant for the smallest positive normal value of the double type.

Constant Value: 2.2250738585072014E-308

public static final double MIN_VALUE

Since: API Level 1

Constant for the minimum double value, 2-1074.

Constant Value: 4.9E-324

public static final double NEGATIVE_INFINITY

Since: API Level 1

Constant for the negative infinity value of the double type.

Constant Value: -Infinity

public static final double NaN

Since: API Level 1

Constant for the Not-a-Number (NaN) value of the double type.

Constant Value: NaN

public static final double POSITIVE_INFINITY

Since: API Level 1

Constant for the positive infinity value of the double type.

Constant Value: Infinity

public static final int SIZE

Since: API Level 1

Constant for the number of bits needed to represent a double in two's complement form.

Constant Value: 64 (0x00000040)

Fields

public static final Class<Double> TYPE

Since: API Level 1

The Class object that represents the primitive type double.

Public Constructors

public Double (double value)

Since: API Level 1

Constructs a new Double with the specified primitive double value.

Parameters
value the primitive double value to store in the new instance.

public Double (String string)

Since: API Level 1

Constructs a new Double from the specified string.

Parameters
string the string representation of a double value.
Throws
NumberFormatException if string cannot be parsed as a double value.

Public Methods

public byte byteValue ()

Since: API Level 1

Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.

Returns
  • the primitive byte value of this object.

public static int compare (double double1, double double2)

Since: API Level 1

Compares the two specified double values. There are two special cases:

  • Double.NaN is equal to Double.NaN and it is greater than any other double value, including Double.POSITIVE_INFINITY;
  • +0.0d is greater than -0.0d

Parameters
double1 the first value to compare.
double2 the second value to compare.
Returns
  • a negative value if double1 is less than double2; 0 if double1 and double2 are equal; a positive value if double1 is greater than double2.

public int compareTo (Double object)

Since: API Level 1

Compares this object to the specified double object to determine their relative order. There are two special cases:

  • Double.NaN is equal to Double.NaN and it is greater than any other double value, including Double.POSITIVE_INFINITY;
  • +0.0d is greater than -0.0d

Parameters
object the double object to compare this object to.
Returns
  • a negative value if the value of this double is less than the value of object; 0 if the value of this double and the value of object are equal; a positive value if the value of this double is greater than the value of object.
Throws
NullPointerException if object is null.
See Also

public static long doubleToLongBits (double value)

Since: API Level 1

Converts the specified double value to a binary representation conforming to the IEEE 754 floating-point double precision bit layout. All Not-a-Number (NaN) values are converted to a single NaN representation (0x7ff8000000000000L).

Parameters
value the double value to convert.
Returns
  • the IEEE 754 floating-point double precision representation of value.

public static long doubleToRawLongBits (double value)

Since: API Level 1

Converts the specified double value to a binary representation conforming to the IEEE 754 floating-point double precision bit layout. Not-a-Number (NaN) values are preserved.

Parameters
value the double value to convert.
Returns
  • the IEEE 754 floating-point double precision representation of value.

public double doubleValue ()

Since: API Level 1

Gets the primitive value of this double.

Returns
  • this object's primitive value.

public boolean equals (Object object)

Since: API Level 1

Tests this double for equality with object. To be equal, object must be an instance of Double and doubleToLongBits must give the same value for both objects.

Note that, unlike ==, -0.0 and +0.0 compare unequal, and NaNs compare equal by this method.

Parameters
object the object to compare this double with.
Returns
  • true if the specified object is equal to this Double; false otherwise.

public float floatValue ()

Since: API Level 1

Returns this object's value as a float. Might involve rounding.

Returns
  • the primitive float value of this object.

public int hashCode ()

Since: API Level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
  • this object's hash code.

public int intValue ()

Since: API Level 1

Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.

Returns
  • the primitive int value of this object.

public static boolean isInfinite (double d)

Since: API Level 1

Indicates whether the specified double represents an infinite value.

Parameters
d the double to check.
Returns
  • true if the value of d is positive or negative infinity; false otherwise.

public boolean isInfinite ()

Since: API Level 1

Indicates whether this object represents an infinite value.

Returns
  • true if the value of this double is positive or negative infinity; false otherwise.

public boolean isNaN ()

Since: API Level 1

Indicates whether this object is a Not-a-Number (NaN) value.

Returns
  • true if this double is Not-a-Number; false if it is a (potentially infinite) double number.

public static boolean isNaN (double d)

Since: API Level 1

Indicates whether the specified double is a Not-a-Number (NaN) value.

Parameters
d the double value to check.
Returns
  • true if d is Not-a-Number; false if it is a (potentially infinite) double number.

public static double longBitsToDouble (long bits)

Since: API Level 1

Converts the specified IEEE 754 floating-point double precision bit pattern to a Java double value.

Parameters
bits the IEEE 754 floating-point double precision representation of a double value.
Returns
  • the double value converted from bits.

public long longValue ()

Since: API Level 1

Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.

Returns
  • the primitive long value of this object.

public static double parseDouble (String string)

Since: API Level 1

Parses the specified string as a double value.

Parameters
string the string representation of a double value.
Returns
  • the primitive double value represented by string.
Throws
NumberFormatException if string cannot be parsed as a double value.

public short shortValue ()

Since: API Level 1

Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.

Returns
  • the primitive short value of this object.

public static String toHexString (double d)

Since: API Level 1

Converts the specified double into its hexadecimal string representation.

Parameters
d the double to convert.
Returns
  • the hexadecimal string representation of d.

public static String toString (double d)

Since: API Level 1

Returns a string containing a concise, human-readable description of the specified double value.

Parameters
d the double to convert to a string.
Returns
  • a printable representation of d.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public static Double valueOf (String string)

Since: API Level 1

Parses the specified string as a double value.

Parameters
string the string representation of a double value.
Returns
  • a Double instance containing the double value represented by string.
Throws
NumberFormatException if string cannot be parsed as a double value.

public static Double valueOf (double d)

Since: API Level 1

Returns a Double instance for the specified double value.

Parameters
d the double value to store in the instance.
Returns
  • a Double instance containing d.