Java初体验之float type

Both C and Java define floating-point types named float and double, which
represent single- and double-precision floating-point values, respectively. Java
floating-point types are, however, represented in a completely different format from
their C/C++ counterparts. As in C, Java floating-point values can be represented
with an exponential portion.

The float type in C is used to store a signed floating-point number value. The
exact size of the float type is specified by the compiler, but in general the int type
is 32 bits (including a sign bit), yielding a range of approximately -34.4E-38 through
3.4E+38. The float type can generally be used safely to store values of six to
seven digits of precision.

The Java float is also used to store signed floating-point number values, but the
language specifies that 32 bits (including a sign bit) are always used to store IEEE
754 floating-point values. Floating-point literals are assumed to be of type double,
so if you specify a float literal you need to append the letter f or F.
The double type in C is used to store a signed floating-point number value. The
exact size of the double type is specified by the compiler, but in general the
double type is 64 bits (including a sign bit), yielding a range of approximately
-1.7E-308 through 1.7E-308. The double type can generally be used safely to store
values of 14 to 15 digits of precision.
The Java double is also used to store signed floating-point number values, but the
language specifies that 64 bits (including a sign bit) are always used to store IEEE
754 floating-point values. Floating-point literals are always assumed to be of type
double, but you can append the letter d or D if you wish.

原文地址:https://www.cnblogs.com/allenblogs/p/2239226.html