I have very strange problems. I have one application where the customer will enter the qusntity and the price, then the program will calculate automatically. Problem is that in some time it gives incorrect numbers, I have one example. Before, this is code:
void calculate_total()
{
int i;
total_bill = 0;
double pre_total;
for (i = 0; i < row_count; i++)
{
TextBox[] textbox_item_array = new TextBox[6];
textbox_item_array = (TextBox[])(item_textbox[i]);
if (textbox_item_array[0].Text != "" && textbox_item_array[4].Text != "" && textbox_item_array[3].Text != "")
{
pre_total = System.Convert.ToInt32(textbox_item_array[4].Text) * System.Convert.ToDouble(textbox_item_array[3].Text);
total_bill = total_bill + pre_total;
}
}
if (double.TryParse(textbox_bill_discount.Text, out bill.bill_discount) == true)
{
textbox_bill_total.Text = total_bill.ToString();
final_total = total_bill - bill.bill_discount;
textbox_bill_final_total.Text = final_total.ToString();
}
else
{
textbox_bill_discount.Text = "";
final_total = total_bill;
textbox_bill_total.Text = total_bill.ToString();
textbox_bill_final_total.Text = final_total.ToString();
}
}
Example of that: if the price is 3.8 and the quantity is 12, the answer should be 45.6. However, the answer is: 45.5555555559.
It is really very strange behavior. Can any help please!!
Best Regards.