It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Casting 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 "Casting" Watch "Casting" New topic


sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
The following line code of code makes no sense to me.
byte b= (byte)(long)(short)16.2;
pl share your comments with me..

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Hi sanjana,
The byte, short, long datatypes can't hold fraction values. What happens in your code, is that 16.2 is treated as double then it is casted to short (16), long(16), byte(16) respectively, hence truncating its value to 16.
[ December 08, 2003: Message edited by: Vicken Karaoghlanian ]

- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Have you checked out Aspose?
subject: Casting
jQuery in Action, 3rd edition