I have products activity i want to count (Float) price * (Integer) quantity for each product than i need the total amount for all products... i tried by this code but the result it's weird orderItems is listview for selected products,
NItems is the quantity, itemprice is the price of each item
total_amount = new StringBuilder();
for (int i = 0; i < orderItems.size(); i++) {
total_amount.append(Integer.parseInt(orderItems.get(i)
.getNItems()) * Float
.parseFloat(orderItems.get(i)
.getItemPrice()));
}
if (total_amount.length()== 0)
return false;
else
total_amount.deleteCharAt(total_amount.length()-1);
Log.d("OrderPreview",total_amount.toString());
You aren't required to put everything on one line. I suggest breaking the statement into multiple parts. I suspect you wanted to use some form of formatted output and generally (for money) you would use
NumberFormat.getCurrencyInstance()
and then format your total with something likeIf you wanted a grand total that should probably be