parsing a string value to double with comma decimal seperator

if there is any one who find a solution to this

string x = "7,50";
string y = "5";
double a = double.Parse(x);
double b = double.Parse(y);
double c = a - b;

then the result must be 2,50.

but I got 70. because of decimal point x is treated as 75.

Jon Skeet
people
quotationmark

Just specify the appropriate culture to double.Parse. For example:

CultureInfo french = new CultureInfo("fr-FR");
double x = double.Parse("7,50", french);

I suspect you actually had "7,5" as a value, however - as "7,50" would be parsed as "750" if you were using a culture which didn't use comma as the separator.

Of course, if these are currency values you should consider using decimal instead of double to start with...

people

See more on this question at Stackoverflow