Java How do I use printf to format this to money with .00 ? public static void main(String[] args) { PaymentBatchProcessor processor = new PaymentBatchProcessor<>(); // create payements: checks(amount) and IOUs(amount) Payment payment1 = new Check(25000.63); Payment payment2 = new IOU(3600.56); Payment payment3 = new Check(250000.64); Payment payment4 = new IOU(36000.56); Payment payment5= new Check(2500.63); Payment payment6= new IOU(36007.56); //Add payments to payment batch Processor processor.add(payment1); processor.add(payment2); processor.add(payment3); processor.add(payment4); processor.add(payment5); processor.add(payment6); //Print out getSize, getMax, getTotal //use printf = "'%5.2f'%n" for money format double System.out.printf("Payments: " + "'%5.2f'%n",processor.getSize()); System.out.printf("Max payment: " + "'%5.2f'%n",processor.getMax()); System.out.printf("Total payment: " +"'%5.2f'%n",processor.getTotal());
Java
How do I use printf to format this to money with .00 ?
public static void main(String[] args) {
PaymentBatchProcessor <Payment> processor = new PaymentBatchProcessor<>();
// create payements: checks(amount) and IOUs(amount)
Payment payment1 = new Check(25000.63);
Payment payment2 = new IOU(3600.56);
Payment payment3 = new Check(250000.64);
Payment payment4 = new IOU(36000.56);
Payment payment5= new Check(2500.63);
Payment payment6= new IOU(36007.56);
//Add payments to payment batch Processor
processor.add(payment1);
processor.add(payment2);
processor.add(payment3);
processor.add(payment4);
processor.add(payment5);
processor.add(payment6);
//Print out getSize, getMax, getTotal
//use printf = "'%5.2f'%n" for money format double
System.out.printf("Payments: " + "'%5.2f'%n",processor.getSize());
System.out.printf("Max payment: " + "'%5.2f'%n",processor.getMax());
System.out.printf("Total payment: " +"'%5.2f'%n",processor.getTotal());
Trending now
This is a popular solution!
Step by step
Solved in 3 steps