Java Reference
In-Depth Information
All real numbers are called
double
literals. A
double
literal may optionally end with
d
or
D
, for example, 19.27d.
However, the suffix d or D is optional in
double
literals. That is, both 19.27 and 19.27d represent the same
double
literal.
This topic uses
double
literals without the suffix
d
or
D
. A
double
literal can be expressed in the following two formats:
•
Decimal number format
•
Examples of
double
literals in decimal number format are as follows:
Scientific notation
double d1 = 8D
double d2 = 8.;
double d3 = 8.0;
double d4 = 8.D;
double d5 = 78.9867;
double d6 = 45.0;
■
Tip
8 is an
int
literal whereas
8D
,
8.
, and
8.0
are
double
literals.
Like a float literal, you can also use scientific notation to express double literals.
double d1 = 32.5E-1;
double d2 = 0.325E+1;
double d3 = 0.325E1;
double d4 = 0.0325E2;
double d5 = 0.0325e2;
double d6 = 32.5E-1D;
double d7 = 0.325E+1d;
double d8 = 0.325E1d;
double d9 = 0.0325E2d;
Like the float data type, the double data type defines two zeros, two infinities, and a
NaN
. They are represented by
constants in the
Double
class. Table
3-4
lists these constants and their meanings. Table
3-4
also lists two constants, which
represent the maximum and minimum (greater than zero)
double
values that can be represented in a
double
variable.
Table 3-4.
double Constants in the Double Class
double Constants
Meaning
Double.POSITIVE_INFINITY
Positive infinity of type
double
Double.NEGATIVE_INFINITY
Negative infinity of type
double
Double.NaN
Not a Number of type
double
Double.MAX_VALUE
The largest positive value that can be represented in a
double
variable. This is equal
to 1.7 x 10
308
(approx.)
Double.MIN_VALUE
The smallest positive value greater than zero that can be represented in a
double
variable. This is equal to 4.9 x 10
-324
.