开发者

Monetary symbol (not $) in DataGridView field values

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开发者_如何学JAVA's important, but values come out of a sql server database from a 'money' type field.


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


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜