System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowThousands;
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
string value;
System.Globalization.NumberStyles style;
System.Globalization.CultureInfo culture;
float number;
value = "1.345,978";
style = System.Globalization.NumberStyles.AllowDecimalPoint |
System.Globalization.NumberStyles.AllowThousands;
culture = System.Globalization.CultureInfo.CreateSpecificCulture("es-ES");
if (Single.TryParse(value, style, culture, out number))
Console.WriteLine("Converted '{0}' to {1}.", value, number);
else
Console.WriteLine("Unable to convert '{0}'.", value);
value = "1 345,978";
if (Single.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