wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "printf and floating point" Watch "printf and floating point" New topic

printf and floating point

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804

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

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

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.

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804

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
I agree. Here's the link: http://aspose.com/file-tools
subject: printf and floating point
Similar Threads
Printf (not enough resources)
Double and Float
why does this print true?
How to change format the following string?
Decimal values