Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse string to decimal with currency symbol?

I have no idea why this is not working:

string s = "12,00 €";
var germanCulture = CultureInfo.CreateSpecificCulture("de-DE");
decimal d;
if (decimal.TryParse(s, NumberStyles.AllowCurrencySymbol, germanCulture, out d))
{
    // i want to get to this point
    Console.WriteLine("Decimal value: {0}", d);
}
like image 778
Tim Schmelter Avatar asked Dec 14 '12 12:12

Tim Schmelter


1 Answers

Use NumberStyles.Currency instead of NumberStyles.AllowCurrencySymbol

if (decimal.TryParse(s, NumberStyles.Currency, germanCulture, out d))

and the output for you code would be:

Decimal value: 12.00
like image 94
Habib Avatar answered Oct 12 '22 13:10

Habib