This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting using printf

 
P Teng
Greenhorn
Posts: 16
  • 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: 20511
54
Chrome Eclipse IDE Java Windows
  • 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