permaculture playing cards*
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
Author

Just a weird doubt

aishwarya mathur
Greenhorn

Joined: Sep 03, 2004
Posts: 22

It outputs 22 ,why not 23
marc weber
Sheriff

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
sscce.org
Dirk Schreckmann
Sheriff

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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Just a weird doubt