Results 1 to 5 of 5
  1. #1
    roofninja is offline Member
    Join Date
    Jul 2012
    Location
    Asheville, NC
    Posts
    14
    Rep Power
    0

    Default 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. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default 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. #3
    roofninja is offline Member
    Join Date
    Jul 2012
    Location
    Asheville, NC
    Posts
    14
    Rep Power
    0

    Default Re: Decimal.Format error

    Here is the error message.
    Decimal.Format error-error.png

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Decimal.Format error

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

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

Similar Threads

  1. How to Format a double value to 2 decimal places
    By nandhinianand in forum New To Java
    Replies: 3
    Last Post: 04-30-2012, 01:26 AM
  2. How do you format to two decimal places with println()?
    By EscSequenceAlpha in forum New To Java
    Replies: 4
    Last Post: 04-05-2012, 08:27 PM
  3. Can't get the decimal format to format correctly...
    By Valerie1067 in forum New To Java
    Replies: 5
    Last Post: 03-25-2012, 04:15 AM
  4. Replies: 7
    Last Post: 09-14-2011, 03:06 PM
  5. Rounding decimal error
    By NixasMuraki in forum New To Java
    Replies: 3
    Last Post: 06-01-2011, 01:07 AM

Posting Permissions

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