• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conversion Doubt

 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Conversion
{
public static void main(String[] args)
{
int i = 1234567890;
float f = i;
System.out.println(i - (int)f);
}
}

The Above Code will Not Print 0.
Why?
#################################
 
Ryan Kade
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agrah,

This has to do with the complex way floats store decimal numbers. Both ints and floats use 32-bits to represent numbers, but the precision on floats varies depending on the kind of significant digits it has to store. Floats tend to be slightly inaccurate as a result and you should not use them to represent values that need accuracy (like money).
 
Thitipong Suparurkrat
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


try this
 
agrah upadhyay
Ranch Hand
Posts: 579
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then How To Solve This Type Of Problem.Plz Also tel Me More Clearly About Significant Digits in Decimal As Well As Binary Number Context

Thanx A Lot
####################################3
Agrah Upadhyay
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic