Mega Code Archive

 
Categories / C# / Data Types
 

Converts string to Decimal using the specified style and culture-specific format

using System; using System.Globalization; class MainClass {     public static void Main( )     {         string value = "987 654,321";         NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;         try         {            decimal number = Decimal.Parse(value, style, CultureInfo.InvariantCulture);              Console.WriteLine("'{0}' converted to {1}.", value, number);         }            catch (FormatException)         {            Console.WriteLine("Unable to parse '{0}'.", value);         }         } }