asp.net中的货币格式字符串
问题描述:
我正在使用infragistics webgrid并需要格式化货币字符串。为此,我需要一个包含“$ ### ###,00”这样的模式的字符串,我希望这个字符串能够从我目前的CultureInfo中获得。我怎样才能做到这一点? 我需要从信息中手动编写它:asp.net中的货币格式字符串
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyGroupSeparator
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyGroupSizes
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyDecimalDigits
CultureInfo.CreateSpecificCulture(myLanguageId).NumberFormat.CurrencyDecimalSeparator
等 等 等
的是一个单行的解决方案?
答
感谢您的所有答案。 事实证明我的要求是错误的。 infragistics网格不希望模式字符串知道哪些分隔符使用,它使用模式字符串作为小数,然后查询当前的文化。 所以这是一个非问题。无论如何感谢 !
答
decimal moneyvalue = 1921.39m;
string s = String.Format("{0:C}", moneyvalue);
将使用当前的文化。
确保你在你的web.config以下:
<system.web>
<globalization culture="auto" uiCulture="auto"/>
</system.web>
或CK表明,申报相当于在你的页面
答
添加到格雷格院长的回答,您可能需要有
Culture="auto" UICulture="auto"
在页面的@Page声明中。
答
首先 - 如果您是文化特定的,为什么不直接使用“C”作为格式字符串,并因此使用文化的货币格式。
Custom numeric format strings没有货币标记;不过,我怀疑你可以将currency symbol附加到从“### ###,00”格式化的字符串中。
答
我们在我们的项目中有几乎相似的要求。 我们所做的就是使用infragistics的webcurrencyedit控制,将其设置为需要显示货币的列的editorcontrolid,然后设置webcurrencyedit控件的区域性。
好吧,不完全。我不想自己做实际的转换,只是得到模式字符串。 像这样: string myPattern = CreateCurrencyPattern(myCurrentCulture); ,然后myPattern将包含带有或不带货币符号的“$ ###,###,###。00”。 – 2009-04-17 09:19:07