For the shipping fees and sub total, I have declared it as double
. However
they just display an amount of 25.0
or 128.0
with just one decimal. I wish to display 25.00
or 128.00
instead. How should I modify my code?
@Override
protected void onResume() {
super.onResume();
// Refresh the data
if(mProductAdapter != null) {
mProductAdapter.notifyDataSetChanged();
}
double totalweight = 0;
double shippingfee = 0;
for(product p : mCartList) {
int quantity = ShoppingCartActivity.getProductQuantity(p);
totalweight += p.weight * quantity;
shippingfee = ShoppingCartActivity.getShipping(totalweight);
}
double subTotal = 0;
for(product p : mCartList) {
int quantity = ShoppingCartActivity.getProductQuantity(p);
subTotal += p.price * quantity;
}
if (subTotal >= 150){
shippingfee = 0;
subTotal += shippingfee;
}
else{
for(product p : mCartList) {
int quantity = ShoppingCartActivity.getProductQuantity(p);
totalweight += p.weight * quantity;
shippingfee = ShoppingCartActivity.getShipping(totalweight);
}
subTotal += shippingfee;
}
TextView productPriceTextView = (TextView)
findViewById(R.id.TextViewSubtotal);
productPriceTextView.setText("Subtotal: RM" + subTotal);
TextView productWeightTextView = (TextView)
findViewById(R.id.TextViewSubweight);
productWeightTextView.setText("Shipping Weight: " + totalweight +" kg");
TextView productShippingTextView = (TextView)
findViewById(R.id.TextViewShipping);
productShippingTextView.setText("Shipping Fee: RM" + shippingfee);
}