如何将$符号更改为₱;在一个文本框中,离开动作监听器c#

如何将$符号更改为₱;在一个文本框中,离开动作监听器c#,c#,C#,货币的默认货币符号是$sign,但是我想以某种方式将其更改为另一种货币。例如,₱或% 这是我目前的代码 private void cash_Leave(object sender, EventArgs e) { double value; if(Double.TryParse(cash.Text, out value)) { cash.Text = String.Format(System.Globalization.CultureInfo.Current

货币的默认货币符号是$sign,但是我想以某种方式将其更改为另一种货币。例如,₱或%

这是我目前的代码

private void cash_Leave(object sender, EventArgs e)
{
    double value;
    if(Double.TryParse(cash.Text, out value))
    {
        cash.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C2}", value);
    }
    else
    {
        cash.Text = String.Empty;
    }
}

₱符号代表菲律宾比索,因此您可以将
CultureInfo
设置为菲律宾文化(英文):

英镑符号代表英国英镑,因此您可以使用英国文化信息(en GB)来获取此符号:

String.Format(new System.Globalization.CultureInfo("en-GB"), "{0:C2}", value)

有关区域设置代码的列表,请参阅。

您必须更改当前区域性的货币符号

i-e 在编写代码之前执行此操作

var newCulture = System.Globalization.CultureInfo.CurrentCulture.Clone() as CultureInfo;
newCulture.NumberFormat.CurrencySymbol = "₱";
Thread.CurrentThread.CurrentCulture = newCulture;

旁注:处理货币时,最好使用
十进制
。使用浮点数进行操作(如
double
)可能会导致一些严重的舍入错误。
var newCulture = System.Globalization.CultureInfo.CurrentCulture.Clone() as CultureInfo;
newCulture.NumberFormat.CurrencySymbol = "₱";
Thread.CurrentThread.CurrentCulture = newCulture;