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

printf and floating point

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

System.out.printf("%f", Math.PI);
Output: 3,141593

So is default: System.out.printf("%.6f", Math.PI); ?


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Charles Chikito
Ranch Hand

Joined: May 22, 2009
Posts: 76
I guess so. My compiler did produced the same output but with a decimal point instead of a comma.

_Charles
Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Dot instead of comma - it is local dependent. printf method takes default Locale.

But 6 fraction digits are disguising - NumberFormat object uses 3 fraction digits by default
 
wood burning stoves
 
subject: printf and floating point