Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 771
  • 1k
  • 50.4k

Input string was not in a correct format.

May 29 2024 9:59 PM

Hello Team,

When I Add Item to the list, I want the itme qty, totalprice,  total tax,amount received, change, grandtotal and overallgrand total listed in the lables.

 public void CalculateTotal()
        {
            //int i = 0;
           
            decimal Sum = 0;
            decimal SubTotal = 0;
            decimal tax = 0;
            decimal discount = decimal.Parse(txt_Discount.Text);
            decimal totalPrice = decimal.Parse(lbl_TotalPrice.Text);
            decimal percentageDiscount = decimal.Parse(lbl_Discount.Text);
            
            for (int i = 0; i <dataGridView1.Rows.Count; i++)
            {
                
                
                Sum =Convert.ToDecimal(Sum + dataGridView1.Rows[i].Cells[9].Value.ToString());
                tax = Convert.ToDecimal(tax + dataGridView1.Rows[i].Cells[4].Value.ToString())/100 * int.Parse(dataGridView1.Rows[i].Cells[7].ToString()) * Convert.ToDecimal(dataGridView1.Rows[i].Cells[6].ToString());
                SubTotal= (Convert.ToDecimal(tax +  dataGridView1.Rows[i].Cells[4].Value.ToString()) * int.Parse(dataGridView1.Rows[i].Cells[7].ToString()));

                lbl_NoOfItems.Text = (dataGridView1.Rows.Count -1 + 1).ToString();
                lbl_SubTotal.Text = SubTotal.ToString("#,##0.00");
                lbl_TotalTax.Text = Convert.ToDecimal(tax + SubTotal).ToString("#,##0.00");
               lbl_Discount.Text = Convert.ToDecimal(discount * totalPrice / 100).ToString("#,##0.00");
                lbl_GrandTotal.Text =Convert.ToDecimal(totalPrice * percentageDiscount).ToString("#,##0.00");

               lbl_OverallGrandTotal.Text = Convert.ToDecimal(lbl_GrandTotal.Text).ToString("#,##0.00");
            }
            
            }

am also having a feedback from this variable saying that input string not in correct format.

decimal discount = decimal.Parse(txt_Discount.Text);

and in the dataGridView I hide the first column


Answers (4)