How to parse 1,2with Single.Parse? The reason for the request is that when I use CultureInfo.InvariantCulture, I don't get 1.2 as I would like, but rather 12.
Should the “Invariant Culture” culture be ignored?
Consider the following example :
using System;
using System.Globalization;
public class Program
{
public static void Main()
{
Console.WriteLine(Single.Parse("1,2", CultureInfo.InvariantCulture));
Console.WriteLine(Single.Parse("1.2", CultureInfo.InvariantCulture));
float value;
Console.WriteLine(Single.TryParse("1,2", NumberStyles.Float, CultureInfo.InvariantCulture, out value));
Console.WriteLine(Single.TryParse("1,2", out value));
Console.WriteLine(value);
}
}
The result of this will be
12
1.2
False
Truth
12
But I was expecting:
1.2
1.2
True
True
1.2
Based on on my reading of InvariantCultureI have to get this result, but I do not.