1

I'm trying to create a Winform that allows a user to select a currency symbol AND a currency format (by inputting the locale for it).

I would like to have a number follow that selected format but yet ignore the default Currency Symbol belonging to .

EX: If a user select "$" as txtCurrencySymbol but wants it formatted in the "hi-IN" Locale, so that it would appear as "$10,00,000" what would the coding be for that?

I found an answer for a question similar to mine, however it is written in JAVA (and I'm using VB.NET).

Currency symbol with another number format

Here is a bit of the coding that I have so far:

    If rbCurrencyDollar.Checked = True Then
        ' We're using the dollar... so, set the Currency Symbol to $
        txtCurrencySymbol.Text = "$"

        ' Set the Locale to en-US
        txtCurrencyLocale.Text = "en-US"

        ' Disable the TXT boxes so that no one can edit them.
        txtCurrencyLocale.Enabled = False
        txtCurrencySymbol.Enabled = False

        'NumberFormatInfo.CurrentInfo.CurrencySymbol = "$"

        Dim nfi = New NumberFormatInfo()

        nfi.CurrencySymbol = "$"
        lblSampleCurrency.Text = 1000000.ToString("C", nfi)

    End If

Now the problem here is that, the number will display not at $1,000,000 but instead as "$1,000,000.00".

Community
  • 1
  • 1
Paul Williams
  • 1,554
  • 7
  • 40
  • 75
  • "Following a Number Format but keeping a different symbol". The symbol is the same in both cases. – djv May 05 '16 at 16:58
  • @Verdolino: Did I word the question badly? I'm essentially trying to programmatically change the numbering system but keep the system selected as the currency symbol to put in the front. – Paul Williams May 05 '16 at 16:59
  • Try `nfi.CurrencyDecimalDigits = 0` – Matt May 05 '16 at 17:37
  • @Matt: That solves one issue. But what about the issue of changing the symbol BUT keeping the numbering system the same. – Paul Williams May 05 '16 at 18:16
  • 1
    NumberFormatInfo also has a way to define the number groupings, you could define some number group arrays and tie them to common locales. https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencygroupsizes(v=vs.110).aspx – Matt May 05 '16 at 18:31
  • @Matt: That article actually got me the correct answer with this line: `Dim nfi As NumberFormatInfo = New CultureInfo(txtCurrencyLocale.Text, False).NumberFormat` now. The label is not appropriately updated on `.TextChanged` As desired! – Paul Williams May 05 '16 at 18:40

0 Answers0