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

Just a weird doubt

aishwarya mathur

Joined: Sep 03, 2004
Posts: 22

It outputs 22 ,why not 23
marc weber

Joined: Aug 31, 2004
Posts: 11343

In casting from a float or double to an integral type, the value is always truncated (everything to the right of the decimal discarded). An explicit cast is always needed in these cases -- even if going from a 32-bit float to a 64-bit long.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
You might like to take a look at section 5.1.3 Narrowing Primitive Conversions of the JLS.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Just a weird doubt
jQuery in Action, 3rd edition