• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My question about Format

 
Maggie Zhou
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nikos Pougounias
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%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 ]
 
Maggie Zhou
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot! Now I see
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic