What's the best way to parse a currency string to a decimal given the
possibility of multiple currencies? That is, my numeric string can be
($12.00) or -£12.00; in either case I want -12.00 to be returned. I
understand that this may be slightly difficult given non-symbol
currency strings (F or Kr) but I figured that the CultureInfo should be
able to take care of it somehow.
The closest solution I came up with, short of iterating through the
string and picking up each number, is the following:
public static decimal StripCurrencySymbol(string number)
{
CultureInfo culture = new CultureInfo("en-GB");
decimal newNumber;
try
{
newNumber = Decimal.Parse(number, NumberStyles.Any, culture);
}
catch
{
throw new Exception("...");
}
return newNumber;
}
The problem is, of course, that since the culture is set to UK, any
string with $ generates an exception. If I set the culture to US, any
string with £ will generate an exception. This problem continues with
the Euro symbol as well.
Is there any way to parse the string given "ANY" culture? I hope this
isn't something simple that I am missing. Thanks.