Please, help me to identify problem in my C# code(WPF, event-handler):
private void Discount5Btn_Click(object sender, RoutedEventArgs e)
{
decimal catPr;
decimal salePr;
string catPrStr;
catPrStr = PriceCatTBox.Text;
catPr = decimal.Parse(catPrStr);
salePr = decimal.Multiply(catPr, 0.95m);
SalePriceTBox.Text = (salePr).ToString("0000.00");
}
I can not make it work – debugger shows error on catPr = decimal.Parse(catPrStr); . Very similar code in another place works. And am I right in such an approach to string-decimal conversion for arithmetic operation?
Edit (added)
Sorry for not specifying catPrStr value, it is from textbox in the following code (in another event-handler):
dlg.PriceCatTBox.Text = "2300.00";
....
and then as above:
catPrStr = PriceCatTBox.Text;
Are you sure your culture (locale) settings aren’t interfering? If
catPrStris always in the invariant culture shown in your edited question, you could usedecimal.TryParse(catPrStr, CultureInfo.InvariantCulture);to force the usage of that culture. If the culture isn’t specified, parsing is done in the current system culture, which might, for example, use a comma as the decimal separator.