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 My question about Format 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 "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
 
wood burning stoves
 
subject: My question about Format
 
Similar Threads
Can we extend multiple classes ?
isNaN function
Dumping the bit values of a primitive type
printf format string question
Calculator program