This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes My question about Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "My question about Format" Watch "My question about Format" New topic
Author

My question about Format

Maggie Zhou
Greenhorn

Joined: Sep 09, 2008
Posts: 26
I have a question about the printf format


I thought the code will throw a exception, but the result is :
123 987.123450

why? I can not understand this


Preparing SCJP 6, try to get high score, and looking for a job...
Nikos Pougounias
Ranch Hand

Joined: Jan 16, 2008
Posts: 110
%2d means: Format an integer and display it with at least 2 characters.

%1f means: Format a floating point and display it with at least 1 character.

An exception would be raised if you switched the arguments: %2$d %1$f

Try it for your self!

Format string syntax
[ September 13, 2008: Message edited by: Nikos Pugunias ]

Nikos' Java blog
Maggie Zhou
Greenhorn

Joined: Sep 09, 2008
Posts: 26
Thanks a lot! Now I see
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My question about Format