DecimalFormat error when compiled
I am new to Java, and having problems with the use of DecimalFormat. When I compile the program it gives me an error so it doesn't work. I am not sure what I am doing wrong. I think that I am using the syntax correctly. When I take out the DecimalFormat it compiles and runs, but I would like the output with commas. What am I doing wrong here?
Code :
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class yeargas
{
public static void main(String[] args)
{
int tank, month;
double year, yearx ,total;
String input;
DecimalFormat formatter=new DecimalFormat(0,000);
//get the average cost to fill 1 tank of gas
input=JOptionPane.showInputDialog("What is the average cost to fill 1 tank of gas? ");
tank=Integer.parseInt(input);
//get the x number of times you fill in a month
input=JOptionPane.showInputDialog("What is the average number of times you fill your car in a month? ");
month=Integer.parseInt(input);
//calculate the cost for a month
//multiply that by 1 year
year=(tank*month)*12;
//get the x number of years to calculate
input=JOptionPane.showInputDialog("How many years do you want to calculate for? ");
yearx=Integer.parseInt(input);
total=yearx*year;
//display the aproximate total cost for x
JOptionPane.showMessageDialog(null,"Your average cost of gas for "+yearx+" is $"+(formatter.format(total))+".");//total+".");
System.exit(0);
}
}
Re: DecimalFormat error when compiled
You need to pass DecimalFormat a String. Put quotes around 0,000.
Also, please post your error in the future.
Re: DecimalFormat error when compiled
Thanks for help. I didn't catch it. I am in a room that is about 93 degrees with a fan as my only saving grace.
How do I do that, so that I can do it the next time around.
Re: DecimalFormat error when compiled
Just tell us what error you are getting when you compile it.
Re: DecimalFormat error when compiled
Re: DecimalFormat error when compiled
THIS SHOULD RUN NOW
...edited by moderator
Re: DecimalFormat error when compiled