File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting using printf

 
P Teng
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one please explain the output caused by line 1



output is below. What causes 559998 to appear after the . instead of just 56
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way floating point numbers are handled on computers. In short, just like you can't represent 1/3 exactly in decimal (0.3333 is an approximation), you can't represent 0.56 or even 0.1 exactly in binary. See this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic