Currency format string in asp.net
Asked Answered
T

5

8

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?

Trigonometry answered 17/4, 2009 at 7:46 Comment(0)
T
1

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!

Trigonometry answered 28/4, 2009 at 11:52 Comment(0)
C
11
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

Chinese answered 17/4, 2009 at 7:50 Comment(2)
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.Trigonometry
This answer doesn't provide the result requested.Flashgun
T
1

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!

Trigonometry answered 28/4, 2009 at 11:52 Comment(0)
M
0

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".

Michiko answered 17/4, 2009 at 7:52 Comment(0)
M
0

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

Culture="auto" UICulture="auto"

in the @Page declaration of your page.

Mariahmariam answered 17/4, 2009 at 7:52 Comment(0)
S
0

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.

Sachet answered 30/6, 2009 at 7:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.