Parse currency values in C#
Converting a decimal value into a currency formatted string is easy. Simply use its ToString method, passing it the parameter "C" as in the following code.
txtAny.Text = value.ToString("C");Strangely parsing a currency value entered by the user is not as simple. By default, decimal.Parse doesn't understand currency symbols or parentheses used to indicate negative values. The solution is to pass decimal.Parse the second parameter NumberStyles.Any, which is defined in the System.Globalization namespace. The following code correctly parses currency values.
decimal value = decimal.Parse(txtValue.Text, NumberStyles.Any);


Comments