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.
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...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.