This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Long -> float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Long -> float" Watch "Long -> float" New topic
Author

Long -> float

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
According the exam guide I am using, it is possible to covert an long value to a float value. They explain the other conversion saying 'widening' which means a 32 bit data type hold a 16 bit data type and so on. But the explanation for my question is not given.
So could you please explain how this is possible. Don't you need a cast to convert a 64 bit long to a 32 but float?
Thank you....


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

The reason this is considered a widening conversion is that the range of possible float values is larger than the range of possible long values. Yes, you can lose precision in converting from long to float, but you don't lose "magnitude," so they decided to allow this conversion without a cast.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Long -> float
 
Similar Threads
Legal Data Types
q on wrapper classes
conversion of primitives scjp
doubt on casting
narrowing the reference