views:

6695

answers:

5

Hi, I am using an infragistics webgrid and need to format a currency string. For this I need a string containing a pattern such as "$ ### ###,00" and I would like this to come out of my current CultureInfo. How can I do this? Do I need to compose it manually from the info in:

CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyGroupSeparator
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyGroupSizes
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyDecimalDigits
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyDecimalSeparator

etc etc etc

Is the a one-line solution?

+1  A: 
decimal moneyvalue = 1921.39m;
string s = String.Format("{0:C}", moneyvalue);

The current culture will be used.

Make sure you have the following in your web.config:

<system.web>
   <globalization culture="auto" uiCulture="auto"/>
</system.web>

or as ck suggests, declare the equivalent, in your page

Greg Dean
well, not quite. I don't want to make the actual conversion myself, just get the pattern string.Like this:string myPattern = CreateCurrencyPattern(myCurrentCulture);and then myPattern would contain "$ ###,###,###.00" with or without the currency symbol.
Mr W
This answer doesn't provide the result requested.
Robert Taylor
A: 

Adding to Greg Dean's answer, you may need to have

Culture="auto" UICulture="auto"

in the @Page declaration of your page.

ck
A: 

First - if you are being culture specific, why not just use "C" as the format string, and hence use the culture's currency format.

Custom numeric format strings don't have a currency token; I suspect, however, that you could just append the currency symbol to the string you get from formatting with "### ###,00".

Marc Gravell
A: 

Hey, thanks for all your answers. It turns out that my requirements were wrong. The infragistics grid does not want a pattern string to know which separators use, it uses the pattern string for decimals and such and then queries the current culture about the rest. So it is a non-issue. thanks anyway!

Mr W
A: 

We had almost similar requirements in our proj. what we did was to use webcurrencyedit control of infragistics, set it as the editorcontrolid for the column for which currency had to be shown and then set the culture of webcurrencyedit control.