I am using the following to display an amount:
String.Format("{0:C}", item.Amount)
This display £9.99
which is okay, but what if I want the application to be able to control the currency and to be able to change the currency to day
$9.99
How do I change the currency format via code
On the Home tab, click the Dialog Box Launcher next to Number. Tip: You can also press Ctrl+1 to open the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Currency or Accounting. In the Symbol box, click the currency symbol that you want.
Choose File > Options > Display. In the Symbol box, type the symbol of the currency that you want to use. In the Placement box, select the position that you want the currency symbol to occupy.
If the currency type is in question, the symbol may include a country prefix, such as CA$, Can$ or C$ for Canadian dollars, or US$ for U.S. dollars. The € symbol is used to represent the euro currency, ¥ represents the Japanese yen, and ƒ signifies a florin, such as the Aruban Florin.
The currency symbol is defined by CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol. The property is read/write but you will probably get an exception if you try to change it, because NumberFormatInfo.IsReadOnly will be true...
Alternatively, you could format the number by explicitly using a specific NumberFormatInfo :
NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone();
nfi.CurrencySymbol = "$";
String.Format(nfi, "{0:C}", item.Amount);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With