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?
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
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With