C# 将字符串转换为同时包含“,”和“.”的浮点数

C# convert string to float containing both "," and "."

我正在解析一个 xml 文件,其中包含像“91.899,74”这样的字符串(这是我所在国家/地区的正确格式),我想使用 float.Parse( ) 但我无法在不替换“.”的情况下让它工作。用“”和“,”用“。”

如果我不进行替换,我会收到输入格式不正确的异常。

关于如何进行转换有什么想法吗?

您需要使用您的文化设置:

CultureInfo culture = new CultureInfo("de");
double number = Double.Parse("202.667,40", culture);

float.Parse() doesn't work the way I wanted

Double parse with culture format