java.lang.Double
java.lang.Number
None
None
JDK 1.0 or later
The Double class provides an object wrapper for a double value. This is useful when you need to treat a double value as an object. For example, there are a number of utility methods that take a reference to an Object as one of their arguments. You cannot specify a double value for one of these arguments, but you can provide a reference to a Double object that encapsulates the double value. Furthermore, as of JDK 1.1, the Double class is necessary to support the Reflection API and class literals.
In Java, double values are represented using the IEEE 754 format. The Double class provides constants for the three special values that are mandated by this format: POSITIVE_INFINITY, NEGATIVE_INFINITY, and NaN (not-a-number).
The Double class also provides some utility methods, such as methods for determining whether a double value is an infinity value or NaN, for converting double values to other primitive types, and for converting a double to a String and vice versa.
public final class java.lang.Double extends java.lang.Number { // Constants public final static double MAX_VALUE; public final static double MIN_VALUE; public final static double NaN; public final static double NEGATIVE_INFINITY; public final static double POSITIVE_INFINITY; public final static Class TYPE; // New in 1.1 // Constructors public Double(double value); public Double(String s); // Class Methods public static native long doubleToLongBits(double value); public static boolean isInfinite(double v); public static boolean isNaN(double v); public static native double longBitsToDouble(long bits); public static String toString(double d); public static Double valueOf(String s); // Instance Methods public byte byteValue(); // New in 1.1 public double doubleValue(); public boolean equals(Object obj); public float floatValue(); public int hashCode(); public int intValue(); public boolean isInfinite(); public boolean isNaN(); public long longValue(); public short shortValue(); // New in 1.1 public String toString(); }
public static final double MAX_VALUE = 1.79769313486231570e+308
The largest value that can be represented by a double.
public static final double MIN_VALUE = 4.94065645841246544e-324
The smallest value that can be represented by a double.
This variable represents the value not-a-number (NaN), which is a special value produced by double operations such as division of zero by zero. When NaN is one of the operands, most arithmetic operations return NaN as the result.
Most comparison operators (<, <=, ==, >=, >) return false when one of their arguments is NaN. The exception is !=, which returns true when one of its arguments is NaN.
This variable represents the value negative infinity, which is produced when a double operation underflows or a negative double value is divided by zero. Negative infinity is by definition less than any other double value.
This variable represents the value positive infinity, which is produced when a double operation overflows or a positive double value is divided by zero. Positive infinity is by definition greater than any other double value.
New as of JDK 1.1
The Class object that represents the type double. It is always true that Double.TYPE == double.class.
The double value to be encapsulated by this object.
Creates a Double object with the specified double value.
The string to be made into a Double object.
If the sequence of characters in the given String does not form a valid double literal.
Constructs a Double object with the value specified by the given string. The string must contain a sequence of characters that forms a legal double literal.
The double value to be converted.
The long value that contains the same sequence of bits as the representation of the given double value.
This method returns the long value that contains the same sequence of bits as the representation of the given double value. The meaning of the bits in the result is defined by the IEEE 754 floating-point format: bit 63 is the sign bit, bits 62-52 are the exponent, and bits 51-0 are the mantissa.
An argument of POSITIVE_INFINITY produces the result 0x7ff0000000000000L, an argument of NEGATIVE_INFINITY produces the result 0xfff0000000000000L, and an argument of NaN produces the result 0x7ff8000000000000L.
The value returned by this method can be converted back to the original double value by the longBitsToDouble() method.
The double value to be tested.
true if the specified value is equal to POSITIVE_INFINITY or NEGATIVE_INFINITY; otherwise false.
This method determines whether or not the specified value is an infinity value.
The double value to be tested.
true if the specified value is equal to NaN; otherwise false.
This method determines whether or not the specified value is NaN.
The long value to be converted.
The double value whose representation is the same as the bits in the given long value.
This method returns the double value whose representation is the same as the bits in the given double value. The meaning of the bits in the long value is defined by the IEEE 754 floating-point format: bit 63 is the sign bit, bits 62-52 are the exponent, and bits 51-0 are the mantissa. The argument 0x7f80000000000000L produces the result POSITIVE_INFINITY and the argument 0xff80000000000000L produces the result NEGATIVE_INFINITY. Arguments in the ranges 0x7ff0000000000001L through 0x7fffffffffffffffL and 0xfff0000000000001L through 0xffffffffffffffffL all produce the result NaN.
Except for NaN values not normally used by Java, this method is the inverse of the doubleToLongBits() method.
The double value to be converted.
A string representation of the given value.
This method returns a String object that contains a representation of the given double value.
The values NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, -0.0, and +0.0 are represented by the strings "NaN", "--Infinity", "Infinity", "--0.0", and "0.0", respectively.
For other values, the exact string representation depends on the value being converted. If the absolute value of d is greater than or equal to 10^-3 or less than or equal to 10^7, it is converted to a string with an optional minus sign (if the value is negative) followed by up to eight digits before the decimal point, a decimal point, and the necessary number of digits after the decimal point (but no trailing zero if there is more than one significant digit). There is always a minimum of one digit after the decimal point.
Otherwise, the value is converted to a string with an optional minus sign (if the value is negative), followed by a single digit, a decimal point, the necessary number of digits after the decimal point (but no trailing zero if there is more than one significant digit), and the letter E followed by a plus or a minus sign and a base 10 exponent of at least one digit. Again, there is always a minimum of one digit after the decimal point.
Note that the definition of this method has changed as of JDK 1.1. Prior to that release, the method provided a string representation that was equivalent to the %g format of the printf function in C.
public static Double valueOf(String s) throws NumberFormatException
The string to be made into a Double object.
The Double object constructed from the string.
If the sequence of characters in the given String does not form a valid double literal.
Constructs a Double object with the value specified by the given string. The string must contain a sequence of characters that forms a legal double literal. This method ignores leading and trailing white space in the string.
New as of JDK 1.1
The value of this object as a byte.
Number.byteValue()
This method returns the truncated value of this object as a byte. More specifically, if the value of the object is NaN, the method returns 0. If the value is POSITIVE_INFINITY, or any other value that is too large to be represented by an byte, the method returns Byte.MAX_VALUE. If the value is NEGATIVE_INFINITY, or any other value that is too small to be represented by an byte, the method returns Byte.MIN_VALUE. Otherwise, the value is rounded toward zero and returned.
The value of this object as a double.
Number.doubleValue()
This method returns the value of this object as a double.
The object to be compared with this object.
true if the objects are equal; false if they are not.
Object.equals()
This method returns true if obj is an instance of Double and it contains the same value as the object this method is associated with. More specifically, the method returns true if the doubleToLongBits() method returns the same result for the values of both objects.
This method produces a different result than the == operator when both values are NaN. In this case, the == operator produces false, while this method returns true. By the same token, the method also produces a different result when the two values are +0.0 and -0.0. In this case, the == operator produces true, while this method returns false.
The value of this object as a float.
Number.floatValue()
This method returns this object value as a float. Rounding may occur.
A hashcode based on the double value of the object.
Object.hashCode()
This method returns a hashcode computed from the value of this object. More specifically, if d is the value of the object, and bitValue is defined as:
long bitValue = Double.doubleToLongBits(d)
then the hashcode returned by this method is computed as follows:
(int)(bitValue ^ (bitValue>>>32))
The value of this object as an int.
Number.intValue()
This method returns the truncated value of this object as an int. More specifically, if the value of the object is NaN, the method returns 0. If the value is POSITIVE_INFINITY, or any other value that is too large to be represented by an int, the method returns Integer.MAX_VALUE. If the value is NEGATIVE_INFINITY, or any other value that is too small to be represented by an int, the method returns Integer.MIN_VALUE. Otherwise, the value is rounded toward zero and returned.
true if the value of this object is equal to POSITIVE_INFINITY or NEGATIVE_INFINITY; otherwise false.
This method determines whether or not the value of this object is an infinity value.
true if the value of this object is equal to NaN; otherwise false.
This method determines whether or not the value of this object is NaN.
The value of this object as a long.
Number.longValue()
This method returns the truncated value of this object as a long. More specifically, if the value of the object is NaN, the method returns 0. If the value is POSITIVE_INFINITY, or any other value too large to be represented by a long, the method returns Long.MAX_VALUE. If the value is NEGATIVE_INFINITY, or any other value too small to be represented by a long, the method returns Long.MIN_VALUE. Otherwise, the value is rounded toward zero and returned.
New as of JDK 1.1
The value of this object as a short.
Number.shortValue()
This method returns the truncated value of this object as a short. More specifically, if the value of the object is NaN, the method returns 0. If the value is POSITIVE_INFINITY, or any other value that is too large to be represented by an short, the method returns Short.MAX_VALUE. If the value is NEGATIVE_INFINITY, or any other value that is too small to be represented by an short, the method returns Short.MIN_VALUE. Otherwise, the value is rounded toward zero and returned.
A string representation of the value of this object.
Object.toString()
This method returns a String object that contains a representation of the value of this object.
The values NaN, NEGATIVE_INFINITY, POSITIVE_INFINITY, -0.0, and +0.0 are represented by the strings "NaN", "--Infinity", "Infinity", "--0.0", and "0.0", respectively.
For other values, the exact string representation depends on the value being converted. If the absolute value of this object is greater than or equal to 10^-3 or less than or equal to 10^7, it is converted to a string with an optional minus sign (if the value is negative) followed by up to eight digits before the decimal point, a decimal point, and the necessary number of digits after the decimal point (but no trailing zero if there is more than one significant digit). There is always a minimum of one digit after the decimal point.
Otherwise, the value is converted to a string with an optional minus sign (if the value is negative), followed by a single digit, a decimal point, the necessary number of digits after the decimal point (but no trailing zero if there is more than one significant digit), and the letter E followed by a plus or a minus sign and a base 10 exponent of at least one digit. Again, there is always a minimum of one digit after the decimal point.
Note that the definition of this method has changed as of JDK 1.1. Prior to that release, the method provided a string representation that was equivalent to the %g format of the printf function in C.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
finalize() |
Object |
getClass() |
Object |
notify() |
Object |
notifyAll() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
Class, Float, Number, NumberFormatException, String
This HTML Help has been published using the chm2web software. |