File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Format Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Format Doubt" Watch "Format Doubt" New topic
Author

Format Doubt

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509


here in line1 4 zeroes are padded. But line2 only 3.

In case of decimal, isnt + sign counted as part of the width?
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
Abhi vijay wrote:

here in line1 4 zeroes are padded. But line2 only 3.

In case of decimal, isnt + sign counted as part of the width?


You are completely wrong here Abhi, in line1 output is:
+12.340000


here no zero padded, as zero padding is done on left side not right side, by default %f shows 6 fractional digits, means 6 digits after a decimal point, so 8 place is already exhausted by %f, so no need to pad any zero on the left side.

In second case it is %d so it will show only +1234 that already took 5 places as + is counted in width, so %+08d will pad only 3 zeros on the left side.

Now run this one:


Remember +,(,.,- all are considered in the width.


SCJP 6
Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509
Ok. Punit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Format Doubt