Decimal.Parse(string, NumberStyles.AllowCurrencySymbol) fails

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Decimal.Parse(money_str, NumberStyles.AllowCurrencySymbol) fails when
money_str = "$22,000.00" (or any currency type string expression created with:
money_str = String.Format( "{0:C}", my_Decimal_variable ); A Format
Exception is thrown and states that the argument was in an incorrect format.
What is the problem?

..NET 1.1
VS2003
C#
Win2k SP4
 
classAct said:
Decimal.Parse(money_str, NumberStyles.AllowCurrencySymbol) fails when
money_str = "$22,000.00" (or any currency type string expression created
with:
money_str = String.Format( "{0:C}", my_Decimal_variable ); A Format
Exception is thrown and states that the argument was in an incorrect
format.
What is the problem?

You need to use a few more flags from the NumberStyle enum to get it to
work. Conveniently, there's a combined flag called "Currency" that should
make things work for you. Like this:

Decimal.Parse(money_str, NumberStyles.Currency)

See this page (MSDN) for information about the various flags available:
http://shrinkster.com/88q


Oliver Sturm
 
Back
Top