double value parse: NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign | NumberStyles.Float | NumberStyles.AllowThousands
using System;
using System.Threading;
using System.Text;
using System.Globalization;
public class Example
{
public static void Main()
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
string value = "(4,321.98)";
NumberStyles styles = NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign | NumberStyles.Float | NumberStyles.AllowThousands;
ShowNumericValue(value, styles);
}
private static void ShowNumericValue(string value, NumberStyles styles)
{
double number;
try
{
number = Double.Parse(value, styles);
Console.WriteLine("Converted '{0}' using {1} to {2}.", value, styles.ToString(), number);
}
catch (FormatException)
{
Console.WriteLine("Unable to parse '{0}' with styles {1}.", value, styles.ToString());
}
}
}
Related examples in the same category