aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how we convert  long into float 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 "how we convert  long into float" Watch "how we convert  long into float" New topic
Author

how we convert long into float

rashid khokhar
Greenhorn

Joined: Mar 12, 2001
Posts: 4
hi ranches,

how we convert larg size of data type like long into small size of data type like float(long==>float) pls explain,read a code of my question.
------------------
Bob Lancaster
Greenhorn

Joined: Feb 21, 2001
Posts: 4
Originally posted by rashid khokhar:
hi ranches,

how we convert larg size of data type like long into small size of data type like float(long==>float) pls explain,read a code of my question.


Simple. Just use an explicit cast. For example:
long longValue = 1234567890L;
float floatValue = (float)longValue;

The explicit cast informs the compiler you are taking responsibility for any loss of data.
See chapter 4 of RHE for a more complete explaination.

-Bob Lancaster
SCJP working on SCJD
Perryn Hodge
Greenhorn

Joined: Mar 22, 2001
Posts: 1
Actually long to float is an automatic promotion, even though some precision may be lost.
so the following will also compile...
long longValue = 1234567890L;
float floatValue = longValue;
 
Consider Paul's rocket mass heater.
 
subject: how we convert long into float