1. Member
Join Date
Jul 2012
Location
Asheville, NC
Posts
14
Rep Power
0

## Decimal.Format error

I am new to Java and just feeling my way around it. I wrote this simple little program with some of the things that I recently learned, but it still gives me 1 error with the Decimal.Format stuff. I think my syntax is correct, but I don't see what I am doing wrong. Am I not using it correctly? What I am wanting, is the program to display the amount with a comma in it.

Java 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.00);
//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))+".");//otal+".");
System.exit(0);
}
}```

2. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
9

## Re: Decimal.Format error

Please post all errors, compile time and/or runtime, otherwise you leave us guessing. My guess: there is not DecimalFormat(int value) constructor. See the docs for this class:
DecimalFormat (Java Platform SE 6)

3. Member
Join Date
Jul 2012
Location
Asheville, NC
Posts
14
Rep Power
0

## Re: Decimal.Format error

Here is the error message.

4. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
9

## Re: Decimal.Format error

Did you read the 2nd and 3rd sentences in post #2?

5. Moderator
Join Date
Jul 2010
Location
California
Posts
1,641
Rep Power
9

## Re: Decimal.Format error

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•