C# convert string to double in locale

前端 未结 1 1382
花落未央
花落未央 2020-12-10 22:26

In my locale the decimal separator is a \',\'.

However I would still like to write a C# application which works with numbers that use the \'.\' as decimal separator.

相关标签:
1条回答
  • 2020-12-10 22:26

    You need to specify the culture as the second argument to double.Parse, e.g.

    double da = double.Parse(a, CultureInfo.InvariantCulture);
    

    Pretty much all of the formatting/parsing methods have overloads taking an IFormatProvider, and the most commonly-specified implementation of IFormatProvider is CultureInfo.

    0 讨论(0)
提交回复
热议问题