I started a course in Java today. One of my exercises is to display 12% of a number rounded to 2 decimal places. I got it all figured out, but something isn't going quite right.
CODE
package ss1;
public class e1b {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/* Create a program that will populate the total sales
for a sales representative, and then the program
will display the 12% commission,
rounded to 2 decimal places.*/
// TODO code application logic here
double dblSales = 100.99, dblComm;
dblComm = dblSales * 0.12;
System.out.format("12 percent of %f %<.2f is %.2f", dblSales, dblComm);
}
}
When I run the program I get this output:
QUOTE
12 percent of 100.990000 100.99 is 12.12
Which isn't what I want it to say. I want it to read:
QUOTE
12 percent of 100.99 is 12.12
I don't know where the four zeros on 100.99 are coming from. If I remove %f from my program, the program doesn't work. So I have no idea.