Results 1 to 5 of 5
Thread: Decimal Fill up
- 07-28-2010, 05:39 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
Decimal Fill up
Hey guys
Below mentioned is a simple program which i wrote that will decide how many digits to display after decimal place.
class Exercise1
{
public static void main(String[] args)
{
double d = 2344.5;
System.out.println("%.5f", d);
}
}
Now as per the above code the output should be 2344.500000, but instead of that i get an error
cannot find symbol, symbol: method println(java.lang.String.double)
location : class java.io.PrintStream
Can anyone help me out with this one????
- 07-28-2010, 05:54 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
- 07-28-2010, 06:00 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
Tht worked
Thanks, that worked. So do i have to use printf every time i use %f or %someother????
Thank you.
- 07-28-2010, 06:10 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
You're welcome of course; read the API documentation for the PrintStream class (System.out is a PrintStream object). The print( ... ) and println( ... ) methods take a single argument while printf( ... ) takes many arguments and uses a Formatter to do the job. The API documents are your friend.
kind regards,
Jos
- 07-28-2010, 06:15 PM #5
Member
- Join Date
- Jun 2010
- Posts
- 45
- Rep Power
- 0
Similar Threads
-
fill table with cells
By BigBear in forum AWT / SwingReplies: 3Last Post: 01-26-2010, 09:22 PM -
How to Fill Arc in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-23-2008, 11:14 PM -
How to Fill a Rectangle in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:10 PM -
How to Fill a Polygon in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:10 PM -
Array Fill Test
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks