【问题标题】:How to show the currency sign after the value in .net?如何在.net中的值之后显示货币符号?
【发布时间】:2013-08-03 05:58:28
【问题描述】:
我在我的asp.net 应用程序中使用波斯文化。
我将价格显示为
PriceLabel.Text = string.Format("{0:C0}", 12000);
这导致12,000 ريال 其中ريال 是波斯货币符号,但我希望货币符号出现在值之后(波斯从左到右,因此,“之后”是指左侧数量)。
我在PriceLabel 上尝试了Style="text-align: right",在包含标签的<td> 标记上尝试了dir="rtl",但这也没有帮助。
【问题讨论】:
标签:
c#
asp.net
globalization
persian
【解决方案1】:
var cultureInfo = new CultureInfo("fa-Ir");
cultureInfo.NumberFormat.CurrencyPositivePattern = 3;
cultureInfo.NumberFormat.CurrencyNegativePattern = 3;
var result = string.Format(cultureInfo, "{0:C0}", 12000);
Console.WriteLine(result);
//Result
//12,000 ريال
【解决方案2】:
.NET 库正在做他们应该做的事情,并以您要求的格式显示货币。要改变这一点,你会破坏 i18n,但如果你知道波斯货币符号的 Unicode 值,你可以尝试使用 String.Format,例如
PriceLabel.Text = string.Format("{0} {1}", 12000, <insert unicode char here>);
我承认这是一个猜测,而且绝对不完美。
【解决方案3】:
当您在文本框中输入时,以下截图将转换为波斯货币格式:
private void textBox3_TextChanged(object sender, EventArgs e)
{
decimal Number;
if (decimal.TryParse(textBox3.Text, out Number))
{
textBox3.Text = string.Format("{0:N0}", Number);
textBox3.SelectionStart = textBox3.Text.Length;
}
}