Question

 double test = Convert.ToDouble("39,618840‎");

this gives me a format exception, and I have tried using the Cultureinfo.invariantculture setting, it does the same.

Was it helpful?

Solution

You have a trailing invisible character after the zero. Remove it.

enter image description here

Then, this works:

var culture = CultureInfo.GetCultureInfo("FR-fr");       
var qty = Convert.ToDouble("39,618840", culture);

OTHER TIPS

There are some invalid characters in that string.

Looking at the hex string we see the following:

"39,618840‎" --> 0x22, 0x33, 0x39, 0x2c, 0x36, 0x31, 0x38, 0x34, 0x30, 0xe2, 0x80, 0x8e, 0x22

And the characters actually look like:

"39,618840â€Ẑ"
        if (myString.Contains(","))
            myString = myString.Replace(",", "");
        double mydouble = Double.Parse(myString);

Using the above method will parse a string into a double, your issue is the comma. If you intended for the comma to act as the decimal point, the following amendment can be made:

        myString = myString.Replace(",", ".");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top