programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Double and Float size

Robbie kyodo
Ranch Hand
Posts: 97
just came across this
float g = 456666666.45454354
//compiler error loss of precision
May i know what is the maximum size that a float and double can store ?
We are not expected to memorize the size of double and float aren't we ? Saw many books stated "not necessary"

John Lee
Ranch Hand
Posts: 2545
float: 32 byte
double: 64 byte
so:
-10^16 <= float <= 10^16 - 1
-10^32 <= float <= 10^32 - 1

Marlene Miller
Ranch Hand
Posts: 1392
May i know what is the maximum size that a float and double can store ?

You may find the constants MAX_VALUE and MIN_VALUE helpful while studying. They are defined in each of the wrapper classes Byte, Short, Integer, Long, Float, Double and Character, but not Boolean.

Marlene Miller
Ranch Hand
Posts: 1392
//compiler error loss of precision

: possible loss of precision
found : double
required: float
float g = 456666666.45454354;
1 error
This error is misleading. The real problem is a number of type double is being assigned to a variable of type float.

Robbie kyodo
Ranch Hand
Posts: 97
Hi Marlene

the example is taken from K&B book, you are right about it. It is a float value that was assigned to a double value.

Robbie kyodo
Ranch Hand
Posts: 97
C:\Temp
>java MaxValue
float max = 3.4028235E38
double max = 1.7976931348623157E308
character max = ?
interger max = 2147483647
long max = 9223372036854775807
short max = 32767
byte max = 127
May I know why character max = ?

John Lee
Ranch Hand
Posts: 2545
i just realized i made a mistake, thanks for the example, it really clear things up!