C # convert string to double in locale

In my locale, the decimal separator is the '.' Character.

However, I would still like to write a C # application that works with numbers using '.' as a decimal separator.

        string b = "0,5";
        double db = double.Parse(b); // gives 0.5

        string a = "0.5";
        double da = double.Parse(a); // gives 5, however i would like to get 0.5
+2
source share
1 answer

You need to specify the culture as the second argument double.Parse, for example

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

Almost all formatting / parsing methods have overloads with IFormatProviderand the most commonly specified implementation IFormatProvider CultureInfo.

+13
source

Source: https://habr.com/ru/post/1538315/


All Articles