Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Double

public final class Double
extends Number implements Comparable<Double>

java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Double


The wrapper for the primitive type double.

See also:

Summary

Constants

int MAX_EXPONENT

Maximum base-2 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 base-2 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)

Returns an integer corresponding to the bits of the given IEEE 754 double precision value.

static long doubleToRawLongBits(double value)

Returns an integer corresponding to the bits of the given IEEE 754 double precision value.

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)

Returns the IEEE 754 double precision float corresponding to the given bits.

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.

Inherited methods

From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

MAX_EXPONENT

Added in API level 9
int MAX_EXPONENT

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

Constant Value: 1023 (0x000003ff)

MAX_VALUE

Added in API level 1
double MAX_VALUE

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

Constant Value: 1.7976931348623157E308

MIN_EXPONENT

Added in API level 9
int MIN_EXPONENT

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

Constant Value: -1022 (0xfffffc02)

MIN_NORMAL

Added in API level 9
double MIN_NORMAL

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

Constant Value: 2.2250738585072014E-308

MIN_VALUE

Added in API level 1
double MIN_VALUE

Constant for the minimum double value, 2-1074.

Constant Value: 4.9E-324

NEGATIVE_INFINITY

Added in API level 1
double NEGATIVE_INFINITY

Constant for the negative infinity value of the double type.

Constant Value: -Infinity

NaN

Added in API level 1
double NaN

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

Constant Value: NaN

POSITIVE_INFINITY

Added in API level 1
double POSITIVE_INFINITY

Constant for the positive infinity value of the double type.

Constant Value: Infinity

SIZE

Added in API level 1
int SIZE

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

Constant Value: 64 (0x00000040)

Fields

TYPE

Added in API level 1
Class<Double> TYPE

The Class object that represents the primitive type double.

Public constructors

Double

Added in API level 1
Double (double value)

Constructs a new Double with the specified primitive double value.

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

Double

Added in API level 1
Double (String string)

Constructs a new Double from the specified string.

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

See also:

Public methods

byteValue

Added in API level 1
byte byteValue ()

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

Returns
byte the primitive byte value of this object.

compare

Added in API level 1
int compare (double double1, 
                double double2)

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 double: the first value to compare.
double2 double: the second value to compare.
Returns
int 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.

compareTo

Added in API level 1
int compareTo (Double object)

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 Double: the double object to compare this object to.
Returns
int 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:

doubleToLongBits

Added in API level 1
long doubleToLongBits (double value)

Returns an integer corresponding to the bits of the given IEEE 754 double precision value. All Not-a-Number (NaN) values are converted to a single NaN representation (0x7ff8000000000000L) (compare to doubleToRawLongBits(double)).

Parameters
value double
Returns
long

doubleToRawLongBits

Added in API level 1
long doubleToRawLongBits (double value)

Returns an integer corresponding to the bits of the given IEEE 754 double precision value. Not-a-Number (NaN) values are preserved (compare to doubleToLongBits(double)).

Parameters
value double
Returns
long

doubleValue

Added in API level 1
double doubleValue ()

Gets the primitive value of this double.

Returns
double this object's primitive value.

equals

Added in API level 1
boolean equals (Object object)

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 Object: the object to compare this double with.
Returns
boolean true if the specified object is equal to this Double; false otherwise.

floatValue

Added in API level 1
float floatValue ()

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

Returns
float the primitive float value of this object.

hashCode

Added in API level 1
int hashCode ()

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
int this object's hash code.

intValue

Added in API level 1
int intValue ()

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

Returns
int the primitive int value of this object.

isInfinite

Added in API level 1
boolean isInfinite (double d)

Indicates whether the specified double represents an infinite value.

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

isInfinite

Added in API level 1
boolean isInfinite ()

Indicates whether this object represents an infinite value.

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

isNaN

Added in API level 1
boolean isNaN ()

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

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

isNaN

Added in API level 1
boolean isNaN (double d)

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

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

longBitsToDouble

Added in API level 1
double longBitsToDouble (long bits)

Returns the IEEE 754 double precision float corresponding to the given bits.

Parameters
bits long
Returns
double

longValue

Added in API level 1
long longValue ()

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

Returns
long the primitive long value of this object.

parseDouble

Added in API level 1
double parseDouble (String string)

Parses the specified string as a double value.

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

shortValue

Added in API level 1
short shortValue ()

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

Returns
short the primitive short value of this object.

toHexString

Added in API level 1
String toHexString (double d)

Converts the specified double into its hexadecimal string representation.

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

toString

Added in API level 1
String toString (double d)

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

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

toString

Added in API level 1
String toString ()

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
String a printable representation of this object.

valueOf

Added in API level 1
Double valueOf (String string)

Parses the specified string as a double value.

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

See also:

valueOf

Added in API level 1
Double valueOf (double d)

Returns a Double instance for the specified double value.

Parameters
d double: the double value to store in the instance.
Returns
Double a Double instance containing d.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.