How do I parse 1,2
with Single.Parse
? The reason of asking is because, when I am using CultureInfo.InvariantCulture
I don't get 1.2 as I would like, but rather 12.
Shouldn't "Invariant Culture" ignore the culture?
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 output of this will be
12
1.2
False
True
12
But I was expecting:
1.2
1.2
True
True
1.2
Based on my reading of InvariantCulture
I should get that result, however I am not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With