File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anyone help me understand the reason behind the output i am getting!

 
sarvesh dikonda
Ranch Hand
Posts: 58
Firefox Browser Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


when i try to compile and run the above code from DOS based command prompt, it gives an output as follows-
100 - 100.000000

i understand anInt is printed as 100 as it is of type integer and its length is 3 (as minimum number of characters (i.e WIDTH ) must be 2 as per the format specifier %2d) but, why is aDouble printed as 100.000000. There must be just two zeroes to sum the the total no. of characters(i.e WIDTH) to 8 as Double is 64bits. So, the output should be 100.0000

And when i try to compile the same above code in Eclipse IDE its showing an error for the statement : System.console().format("%2d - %1f", anInt, aDouble);
The method format(String, Object[]) in the type Console is not applicable for the arguments (String, int, double)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
%1f - format string with as many numbers , but *it always gives 6 decimal places*, hence that output.
 
sarvesh dikonda
Ranch Hand
Posts: 58
Firefox Browser Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seetharaman Venkatasamy wrote:%1f - format string with as many numbers , but *it always gives 6 decimal places*, hence that output.

Thanks Seetharaman Venkatasamy, but what is the answer to the second part of question.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic