Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果有人找到解决方案
string x = "7,50"; string y = "5"; double a = double.Parse(x); double b = double.Parse(y); double c = a - b;
那么结果必须是 2,50。
但我得到了 70。因为小数点 x 被视为 75。
只需指定适当的文化到double.Parse. 例如:
double.Parse
CultureInfo french = new CultureInfo("fr-FR"); double x = double.Parse("7,50", french);
我怀疑您实际上将“7,5”作为值,但是-如果您使用不使用逗号作为分隔符的文化,“7,50”将被解析为“750”。
当然,如果这些是货币值,您应该考虑使用decimal而不是double开始...
decimal
double