title: Formatting two decimal places or currency of double Java
body: <p>I want to figure out how I can format the output as money. As I am a beginner at Java, I would like the most simple solution possible although I am open to all suggestions.</p>
  
  <pre><code>public static void main(String[] args) 
   {
      int numUnits;
      double price;
      String item;
      Scanner scan = new Scanner(System.in);
  
      // get the data
      System.out.println("How many units?");
      numUnits = scan.nextInt();
  
      System.out.println("What is the price?");
      price = scan.nextDouble();
  
      scan.nextLine();
      System.out.println("What is the name of the item?");
      item = scan.nextLine();
  
      //calculations
      double totalCost = numUnits * price;
  
      System.out.println(numUnits + " units of "+ item + " were purchased for $"+
      price + " each for a total cost of $" + totalCost);
  
     }
  
   }
  </code></pre>