Q:

Why does comma (",") disappear when converting string to float in c#.

Currently I am doing this way.
string strPoint = "12.5";
string strComma = "12,5";

Console.WriteLine("strPoint: " + float.Parse(strPoint,System.Globalization.CultureInfo.InvariantCulture));

Console.WriteLine("strComma: " + float.Parse(strComma,System.Globalization.CultureInfo.InvariantCulture)); 

Result:
strPoint: 12,5 and strComma: 125.
strComma must be 12.5? what could be the reason behind this. Please advise.

A:

Remove the InvariantCulture from second Parse.Use your current culture.The decimal separator of InvariantCulture is dot,not comma.You can verify that using :
CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalSeparator;

In first code snippet you are using dot as a separator and using the InvariantCulture for Parse and it is parsing correctly because the InvariantCulture uses dot as a separator.
In the second code snippet you are using comma and it is truncated because it is not the decimal separator of InvariantCulture, the same culture can not use two different separators at the same time.

