File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 24166
    
  30

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
q on wrapper classes
doubt on casting
conversion of primitives scjp
narrowing the reference
Legal Data Types