Console.WriteLine(Convert.ToDouble(“23,23”) + 1);
In this case, the comma is being interpreted as your localization's group separator symbol, and is ignored. See http://msdn.microsoft.com/en-us/library/fd84bdyt.aspx.
Console.WriteLine(Convert.ToInt32(“23,23”) + 1);
In this case, you are using Int32.Parse
, which doesn't support group separators by default.
The reasoning behind this is that the integer converter has no localization support by default, because localization adds an additional overhead and there is no reason to add it for a parser that doesn't need to interact with any symbols at all. You can, however, force the parser to support localization with some extra arguments:
int.Parse("11,23", NumberStyles.AllowThousands, CultureInfo.InvariantCulture);
Float/double conversion, on the other hand, have to support a decimal separator. In some cultures, this is ","
, in others, it can be " "
or "."
. Since the function must support localization anyway, it would make no sense for it to only support some localization features by default. Otherwise, the implementation would confuse people who expect that since localization is supported for decimal separator, it would support other localization aspects as well.