aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why is a good idea do casting if there is a possibility of lose precision? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why is a good idea do casting if there is a possibility of lose precision?" Watch "Why is a good idea do casting if there is a possibility of lose precision?" New topic
Author

Why is a good idea do casting if there is a possibility of lose precision?

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234



Why is a good idea do casting if I can less precision?

André AS
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
How about if you want to lose precision?
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
I heard about that if is not a specific primitive type for specified situation I can lose precision... got it?
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
look at an exemple:




It will print a non-exact number... "1" intead of 1.5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

Look up integer.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40


You should also understand the distinction between implicit and explicit casting. With explicit casting, it means that the programmer wants the data type casted, and will take responsibility for any lost of precision.

So... why cast? Because the program needs the data in that type, and the programmer took care of possible lost of precision.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Why is a good idea do casting if there is a possibility of lose precision?