aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Plz clarify 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 "Plz clarify" Watch "Plz clarify" New topic
Author

Plz clarify

Ankith suresh
Ranch Hand

Joined: Jun 07, 2007
Posts: 42
int intNumber = 123456789;
float floatNumber = intNumber;
int x = (int)floatNumber;
System.out.println(intNumber - x);
I m geting result -3 .how?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

Keep in mind that a floating point number has both a range and precision. While the range of a float can easily hold an int, it may not have the precision to hold all int values accurately.

Anyway, print out the float value -- just to see exactly what value is being held. You will notice that it is slightly off.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Saurabh Verma
Ranch Hand

Joined: Aug 13, 2007
Posts: 38
float floatNumber = intNumber;

After this floatNumber = 1.23456792E8

And when it assignd to x , x = 123456792

Thats why intNumber - x printing -3.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Plz clarify