Double TryParse, NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands
using System;
using System.Globalization;
class MainClass{
public static void Main(){
string value;
NumberStyles style;
CultureInfo culture;
double number;
value = "1.2345,978";
style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
culture = CultureInfo.CreateSpecificCulture("es-ES");
if (Double.TryParse(value, style, culture, out number))
Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
Console.WriteLine("Unable to convert '{0}'.", value);
value = "1 2345,978";
if (Double.TryParse(value, style, culture, out number))
Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
Console.WriteLine("Unable to convert '{0}'.", value);
}
}
Related examples in the same category