如何解析字符串,货币符号为十进制?(How to parse string to decimal w

2019-07-05 07:37发布

我不知道为什么这是不工作:

string s = "12,00 €";
var germanCulture = CultureInfo.CreateSpecificCulture("de-DE");
decimal d;
if (decimal.TryParse(s, NumberStyles.AllowCurrencySymbol, germanCulture, out d))
{
    // i want to get to this point
    Console.WriteLine("Decimal value: {0}", d);
}

Answer 1:

使用NumberStyles.Currency代替NumberStyles.AllowCurrencySymbol

if (decimal.TryParse(s, NumberStyles.Currency, germanCulture, out d))

并为你输出代码如下:

Decimal value: 12.00


Answer 2:

试试这个;

 string.Format(new CultureInfo("en-SG", false), "{0:c0}", 123423.083234);

它会转换123423.083234至1,23,423 $格式。



文章来源: How to parse string to decimal with currency symbol?