UrbanTwitch
01-27-2010, 01:53 AM
I am stuck on this part of my assignment. The DecimalFormat is hard to understand.
My book says...
"Write an application that accepts a double number and then displays it in five different ways, using a combination of dollar signs, thousand seperators, decimal places, and other formats. Use the Java API to look up DecimalFormat and discover some formatting patterns that were not covered in this chapter. Use at least two patterns from the API."
Now here is what I have so far, to show you my progress:
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class formatDan {
public static boolean done;
public static void main(String args[]) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream);
while (!done) {
System.out.println("\n\nPlease type decimal number in:");
String strNum = bufRead.readLine();
try {
double intNumOne = Double.parseDouble(strNum);
NumberFormat formatter = new DecimalFormat("#0.000");
System.out.println("\n\nThe Decimal Value is:"+formatter.format(intNumOne));
}catch (NumberFormatException e)
{
System.out.println("\nWrong number syntax.");
}
}
} //public statc
} // public class
Can you lead me in the right direction? I tried reading my book but then again I'm not efficient in English.. maybe you can help me? :)
Thanks.
My book says...
"Write an application that accepts a double number and then displays it in five different ways, using a combination of dollar signs, thousand seperators, decimal places, and other formats. Use the Java API to look up DecimalFormat and discover some formatting patterns that were not covered in this chapter. Use at least two patterns from the API."
Now here is what I have so far, to show you my progress:
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class formatDan {
public static boolean done;
public static void main(String args[]) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStreamReader istream = new InputStreamReader(System.in) ;
BufferedReader bufRead = new BufferedReader(istream);
while (!done) {
System.out.println("\n\nPlease type decimal number in:");
String strNum = bufRead.readLine();
try {
double intNumOne = Double.parseDouble(strNum);
NumberFormat formatter = new DecimalFormat("#0.000");
System.out.println("\n\nThe Decimal Value is:"+formatter.format(intNumOne));
}catch (NumberFormatException e)
{
System.out.println("\nWrong number syntax.");
}
}
} //public statc
} // public class
Can you lead me in the right direction? I tried reading my book but then again I'm not efficient in English.. maybe you can help me? :)
Thanks.