文本框货币几个国家

时间:2014-04-29 01:41:54

标签: vb.net textbox currency countries

我发现从这些代码行中我们可以获得加拿大的货币。

 Dim value As Decimal = ourTextbox.text 
    Dim positiveValue As Decimal = ourTextbox.text 
    Dim customCurrencyInfo As CultureInfo = CultureInfo.CreateSpecificCulture("fr-CA")

    customCurrencyInfo.NumberFormat.CurrencyNegativePattern = 8

    Dim formatString As String = value.ToString("C", customCurrencyInfo)
    Dim formatStringPositive As String = positiveValue.ToString("C", customCurrencyInfo)

    myTextbox.text = formatString
    myTextbox2.text = formatStringPositive

输出将是;

  

-123,45 $ 123,45 $

但这些国家呢?

-Malaysia
- 印度尼西亚
-Somalia / Africa
-Arabia

如何在格式化文本框中显示其货币?

1 个答案:

答案 0 :(得分:0)

将不同的文化名称作为CreateSpecificCulture()方法的参数传递,例如:

'Malaysia'
Dim customCurrencyInfo As CultureInfo = CultureInfo.CreateSpecificCulture("my-MY")
'Indonesia'
Dim customCurrencyInfo As CultureInfo = CultureInfo.CreateSpecificCulture("id-ID")
'Afrikaans'
Dim customCurrencyInfo As CultureInfo = CultureInfo.CreateSpecificCulture("af")
'Arabic'
Dim customCurrencyInfo As CultureInfo = CultureInfo.CreateSpecificCulture("ar")

您可以在MSDN中找到文化名称列表:CultureInfo Class

注意:更改文化信息不仅会更改货币符号,还可能会更改小数和千位分隔符。如果您想避免这种情况,可以复制当前文化

info and simply change it's currency symbol from other culture :
Dim customCurrencyInfo = (CultureInfo)CultureInfo.CurrentCulture.Clone();
Dim culture As CultureInfo = CultureInfo.CreateSpecificCulture("id-ID")
customCurrencyInfo.NumberFormat.CurrencySymbol = culture.NumberFormat.CurrencySymbol