Two Laptop Bag
The moose likes Beginning Java and the fly likes formatting using printf Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "formatting using printf" Watch "formatting using printf" New topic
Author

formatting using printf

P Teng
Greenhorn

Joined: Nov 20, 2009
Posts: 16
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

Joined: Oct 27, 2005
Posts: 19216

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.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: formatting using printf
 
Similar Threads
printf() doubt
format()
Formatter question
Formatting with printf() and format
Formating with printf() and format()