c# - how can i round off my value based on user input? -
i have code in updatetobill code. im planning round off nearest tenth think? example price 123456.123456, want have 123456.12 because since price, need cents. in advance :)
private void updatetotalbill() { double vat = 0; double totalprice = 0; long totalproducts = 0; foreach (datalistitem item in dlcartproducts.items) { label pricelabel = item.findcontrol("lblprice") label; // price textbox productquantity = item.findcontrol("txtproductquantity") textbox; // quantity double productprice = convert.toint64(pricelabel.text) * convert.toint64(productquantity.text); //computation fro product price. price * quantity vat = (totalprice + productprice) * 0.12; // computation total price. total price + product price totalprice = totalprice + productprice+40 +vat; totalproducts = totalproducts + convert.toint32(productquantity.text); } label1.text = convert.tostring(vat); txttotalprice.text = convert.tostring(totalprice); // put both total price , product values , converting them string txttotalproducts.text = convert.tostring(totalproducts); }
just round math.round
like;
math.round(totalprice, 2) // 123456.12
also can use math.round(double, int32, midpointrounding)
overload specify midpointrounding
awayfromzero
or toeven
. toeven
default option.
Comments
Post a Comment