*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Double and Float size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Double and Float size" Watch "Double and Float size" New topic
Author

Double and Float size

Robbie kyodo
Ranch Hand

Joined: May 05, 2003
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"


SCJP 2 1.4
John Lee
Ranch Hand

Joined: Aug 05, 2001
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

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 05, 2003
Posts: 1391
//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

Joined: May 05, 2003
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

Joined: May 05, 2003
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

Joined: Aug 05, 2001
Posts: 2545
i just realized i made a mistake, thanks for the example, it really clear things up!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Double and Float size
 
Similar Threads
Float
why float f=1/3 is 0?
when i use float gg =10f;// flaot gg = 10;
Automatic type promotion
question on wrapper class