I want to display the total price of ordered meals in a textbox. Now, it looks like "1800", but i would like to make it look like "1.800". The problem is, if I just try to Insert a "." into the string value, then it won't work due to the fact that the total price could change, if the user orders another meal. How can i keep that format if I know the total price could change?
private void fillTotalCostTextBox()
{
textBox_totalPrice.Text = "0";
foreach (DataGridViewRow row in dataGridView_orders.Rows)
{
textBox_totalPrice.Text =
(Convert.ToInt32(textBox_totalPrice.Text) +
Convert.ToInt32(row.Cells["price"].Value)).ToString();
}
}
You should use String.Format Method, as you can see on example bellow:
string s = "1800";
string s = string.Format("{0:#,0.#}", float.Parse(s));