I have the following code which outputs incorrectly.

public static void extend(ArrayList priceList, ArrayList quantityList, ArrayList amountList){
	
		for(int i = 0; i < priceList.size(); i++){
			amountList.add((Double)priceList.get(i) * (Double)quantityList.get(i));
			
			System.out.println(priceList.get(i) + " * " + quantityList.get(i) + " = " + amountList.get(i) );
		}

The output for some of the items is like "18.32 * 5.4 = 98.92800000000001"

I need to round that to two decimal places but everything I try blows everything up.

Advice?

Nevermind I got it - I must have made a typo or something before because it works now - just in case anyone looks here it is

public static void extend(ArrayList priceList, ArrayList quantityList, ArrayList amountList){
	
		for(int i = 0; i < priceList.size(); i++){
			amountList.add((Double)priceList.get(i) * (Double)quantityList.get(i));
			DecimalFormat formatter = new DecimalFormat("0.00");
			System.out.println((i+1) + ")" + priceList.get(i) + " * " + quantityList.get(i) + " = " + formatter.format(amountList.get(i)) );
		}		
	}
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.