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

Long -> float

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
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

Joined: Jul 08, 2003
Posts: 24199

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:
subject: Long -> float
It's not a secret anymore!