문제

I'm using Persian culture in my asp.net application.

I show prices as

PriceLabel.Text = string.Format("{0:C0}", 12000);

Which results in 12,000 ريال where ريال is the Persian currency sign, but I want the currency sign to come after the value (Persian is left to right, so, by "after", I mean to the left side of the number).

I have tried Style="text-align: right" on PriceLabel, and dir="rtl" on the <td> tag containing the label, but that didn't help either.

도움이 되었습니까?

해결책

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 ريال

다른 팁

The .NET libraries are doing what they should be, and showing the currency in the format you requested. To change this, you would be breaking i18n, but you might try using String.Format if you know the Unicode value for the Persian currency sign, e.g.

PriceLabel.Text = string.Format("{0} {1}", 12000, <insert unicode char here>);

I will freely admit that this is a guess, and definitely not perfect.

The following snipped will convert to the Persian money format when you are typing in the text box:

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;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top