I am having a problem getting the sales part of this to display a $ sign and 2 decimal places.
Where would I have to insert the command to have that display as $45000.00? One other question is there a way to get this to display the result all on one line. I have the commission displaying as it should but I can't figure out who to get the sales to display with the decimal places and $ sign.

Thanks for any help!

public class Commission2 {
       public static void main(String[] args) {
	double sales = 45000.0; 
         double commission = 0.0;
         int rate = 5;
         commission = computeCommission(sales, rate);

         System.out.println("Commission on sales of "
                +sales
                + " with a rate of " + rate + "%"
                + " is ");

         System.out.printf("$%.2f\n",commission); 

          
      
         commission = computeCommission (sales);
         
         System.out.println("Commission on sales of "
                +sales
                + " with a rate of 7.5%"
                + " is"); 
      System.out.printf("$%.2f\n",commission); 

                     
         
      }
      public static double computeCommission(double s, double r) {
         return (( (double) r / 100.0) * s);
      }
       public static double computeCommission(double s, int r) {
         return (( (double) r / 100.0) * s);
      }
       public static double computeCommission(double s) {
         return (( 7.5 / 100.0) * s);
      
      
      
      //Calling a method from another class Commission.display(y);
      }
   }

Use the Decimal/Number format API's! =)

I am a newbie. What is that?

You should use classes for NumberFormat or DecimalFormat. You have to create an instance of these. then call the format method I guess with your number and format. Check the class references and search google for example. The idea is you need to define a format and then apply that format to a number.

In your print function, you can manually provide $ sign.

Just ideas--not the exact solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.