views:

52

answers:

2

I'm building an application that is for a non-profit in Guatemala. Everything in the system is in Quetzales, which is denoted with a Q (i.e. Q100.00) is 100 Quetzales.

I need to be able to modify the monetary values in any DataGridView column, but I've been unable to figure out an easy way to do it with formatting like you can with a dollar sign. I don't want to use computer region settings because some people using the system, use computers from the US.

Not sure if it's important, but values come out of a sql server database from a 'money' type field.

+2  A: 

When formatting a string you can specify which culture you want to use:

decimal cost = 1500m;
string s = cost.ToString("C", CultureInfo.GetCultureInfo("es-GT"));

Result

Q1,500.00
Mark Byers
Excellent! I imagine this is exactly what I need to format all the data in the columns. Thanks!
Ricky
+2  A: 

If you do not want to rely on the Regional settings you can force the application to execute using the Guatamala culture regardless of the regional settings.

CultureInfo culture = new CultureInfo("es-GT");
decimal amount = 123.43M;

// Set the culture for the thread
System.Threading.Thread.CurrentThread.CurrentCulture = culture;

// Uses the thread culture for formatting
MessageBox.Show(amount.ToString("c"));

// Alternatively if you do not want to set the thread culture
// you can explicitly format using the passed culture
MessageBox.Show(amount.ToString("c", culture));
Chris Taylor
Awww. When I see stuff like this, I really think I'd like to switch to C# one day. (Coming from PHP) Sweet!
Pekka