• Post Reply Bookmark Topic Watch Topic
  • New Topic

type double  RSS feed

 
Martyn Clark
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi while using the type double if i give the variable the value say 300.00
when i print this value to the screen i only get 300.0, i want the last 0 to print as well. please can anyone one explain this for me.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
300.00 and 300.0 are, of course, the same number, so assigning one or the other to a double makes no difference; it will always print in the default format.

If you want to print a number using a specific format, you can use the System.out.printf() method in JDK 1.5, or the java.text.DecimalFormat class in older versions of Java. The Javadocs for each give usage examples.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!