使用CultureInfo时如何在数字前面显示欧元符号?

How to display the euro symbol at the front of the number when using CultureInfo?

所以我想尝试用C#显示货币并找到CultureInfo,唯一的问题是,没有办法在数字前面显示欧元符号,不是我看到和读到的。

基本上是这样的:

float f = 100.50;
MoneyAmount.Text = f.ToString("C", new CultureInfo("en-GB"));

将显示:£100.50

这个:

float f = 100.50;
MoneyAmount.Text = f.ToString("C", new CultureInfo("en-US"));

将显示:$100.50

但是这个:

float f = 100.50;
MoneyAmount.Text = f.ToString("C", new CultureInfo("fr-FR"));

将显示:100.50 €

有什么方法可以让 fr-FR 像这样显示货币:€100.50?

您可以设置 CultureInfo 实例的 NumberFormat.CurrencyPositivePatternNumberFormat.CurrencyNegativePattern:

float f = 100.50f;
var culture = new CultureInfo("fr-FR");
culture.NumberFormat.CurrencyPositivePattern = 0;
culture.NumberFormat.CurrencyNegativePattern = 2;
culture.NumberFormat.CurrencyDecimalSeparator = CultureInfo.InvariantCulture.NumberFormat.CurrencyDecimalSeparator;
Console.WriteLine(f.ToString("C", culture));

版画

    €100.50

您可以自定义文化信息;

var frenchCulture = new CultureInfo("fr-FR");
frenchCulture.NumberFormat.CurrencyPositivePattern = 0;
frenchCulture.NumberFormat.CurrencyNegativePattern = 2;
frenchCulture.NumberFormat.CurrencyDecimalSeparator = ".";
double value = 100.50;
Console.WriteLine(value.ToString("C", frenchCulture)); // Output : €100.50
value = -100.50; //For negative currency
Console.WriteLine(value.ToString("C", frenchCulture)); // Output : €-100.50

谁用 "put en-FR instead of fr-FR" 发表评论,所以它看起来像这样:

MoneyAmount.Text = f.ToString("C", new CultureInfo("en-FR"));

谢谢阿德里安,你成功了。我认为 en-FR 不存在,因为我发现的唯一东西是 fr-FR.

您可以使用 CurrencyPositivePattern 属性 关于您的 CultureInfo 中的 NumberFormatInfo class。使用值2时,会改变数字前货币符号的位置。