File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

formatting conversion

 
sentil kumar
Ranch Hand
Posts: 74
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.printf("%s",new Float(11)); - prints 11.0
System.out.printf("%d",new Float(11));
throw java.util.IllegalFormatConversionException: d != java.lang.Float.

first printf statement implies that (String) s == java.lang.Integer
how the first prinf statement runs fine.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Format string syntax API documentation says this about %s


Conversion: 's', 'S'
Argument Category: general
Description: If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invoking arg.toString().

Float doesn't appear to implement Formattable, but it has a toString() method.
[ November 23, 2006: Message edited by: Carol Enderlin ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic