Reputation: 305
Imagine I have the following values in a string, example:
string[] values = new string[] { "17.424", "44.43", "44.0"};
Now I need to extract the exact value with the respective comma and save them as Double Numeric Type.
double valuesCorrectType;
I don't want to use this:
Convert.ToDouble(string);
because the output I get is: 17424.0 and 4443.0 and 44.0
How can I achieve this?
Upvotes: 0
Views: 74
Reputation: 223372
Just pass CultureInfo.InvariantCulture
double d = Convert.ToDouble("17.424", CultureInfo.InvariantCulture);
Its your current culture which is considering .
as thousand separator.
You can also use double.Parse
or double.TryParse
, but you have to specify CultureInfo.InvariantCulture
Upvotes: 6