Parse string with thousands separator and decimal separator to decimal in CSharp
Description
The following code shows how to parse string with thousands separator and decimal separator to decimal.
Example
using System;/*w w w .j av a 2 s .com*/
using System.Globalization;
class MainClass
{
public static void Main( )
{
string value = "987 654,321";
NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
CultureInfo provider = new CultureInfo("fr-FR");
decimal number = Decimal.Parse(value, style, provider);
Console.WriteLine("'{0}' converted to {1}.", value, number);
}
}
The code above generates the following result.