my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes code of my previous question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "code of my previous question" Watch "code of my previous question" New topic

code of my previous question

rashid khokhar

Joined: Mar 12, 2001
Posts: 4
link with long==>float
class myclass{
float i;//float have 32 bits.
long j;//long have 64 bits.
void method(){
i=j;// convert long into float
class tester{
public static void main(String agrs[]){
myclass my=new myclass();
output = 2043223.0

Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Hi Rashid,
quoting Rana Thakur:
Rana Thakur
greenhorn posted February 27, 2001 08:14 AM
The value for a long variable will be stored as 64 bits.
However the floating point value will be stored in 32 bits in IEEE floating point format.i.e left most bit for sign bit, next 7 bits from the left for exponent and the remaining 24 bits for mantissa. Thus the value that can be stored using this format(maximum value being 3.4E+038) is much higher than that of the value that can be stored in a simple long variable(max value (2^63)-1). Hence the conversion is widening and not narrowing.

There was some discussion about this point in the forum. Search for "float".
A float can take up a higher value then a long. The cost is lower precicion.
hope this helps
I agree. Here's the link:
subject: code of my previous question
jQuery in Action, 3rd edition