Question

I want to format a DataGridView column which shows money values, however I want to use a custom currency prefix, which is not currently defined by any culture. I want my values to look like this:

Mn. 2,300.00
Mn. 40,259.22
Mn. 6.33
Mn. 2,000,203.19

Obviously, Mn. is the prefix I want to add. Other than this customization, the value itself is to be formatted like any other currency (i.e. 2 decimal places, commas after every 3 digits, etc ..)

Was it helpful?

Solution 2

You'll want to manage your own NumberFormatInfo object, which contains a CurrencySymbol property. You can pass this object to the decimal.ToString() method.

var format = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
format.CurrencySymbol = "Mn. ";
var amount = 12345.67m;
Console.WriteLine(amount.ToString("C", format));

OTHER TIPS

(This self-answer was previously posted by the question OP as an edit to the question. Content migrated to this answer.)

var format = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();  
format.CurrencySymbol = "Mn. ";  
qBDDataGridView.Columns["Base Selling Price"].DefaultCellStyle.FormatProvider = format;  
qBDDataGridView.Columns["Base Selling Price"].DefaultCellStyle.Format = "c";  

The above will format a column named "Base Selling Price" in that DataGridView to use the custom symbol 'Mn.' for the currency. Hope this proves to be useful to others too. Credit goes to the answer by Jason Whitted which led me (the question OP) in the right direction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top