c# - 改变文化时如何只保留一个标准货币符号($)?
问题描述
无论选择何种语言/国家,如何使网络应用程序仅以美元显示货币?
SetCulture(string culture)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(culture);
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo(culture);
}
Text = String.Format("{0:C}", item.TotCostDay);
解决方案
您可以尝试通过修改创建Clone
当前文化NumberFormat.Currency...
:
CultureInfo culture = CultureInfo.CurrentCulture.Clone() as CultureInfo;
CultureInfo usCulture = CultureInfo.GetCultureInfo("en-US");
// Dollar symbol - $
culture.NumberFormat.CurrencySymbol = usCulture.NumberFormat.CurrencySymbol;
// And (may be) some US currency patterns
culture.NumberFormat.CurrencyDecimalDigits = usCulture.NumberFormat.CurrencyDecimalDigits;
culture.NumberFormat.CurrencyPositivePattern = usCulture.NumberFormat.CurrencyPositivePattern;
culture.NumberFormat.CurrencyNegativePattern = usCulture.NumberFormat.CurrencyNegativePattern;
CultureInfo.CurrentCulture = culture;
推荐阅读
- react-native - textContentType=oneTimeCode 不适用于 iOS
- c++ - 如何在结束 C++ 命令行应用程序时运行函数?
- php - 这个 PHP 类常量声明有什么问题?
- reactjs - npm run build - 尽管开发版本工作正常,但无法编译
- node.js - 无法在 Webpack 3 中将 Sass 添加到 Vue 项目
- javascript - 如何使用 Javascript 计算 Acrobat PDF 中的字段?
- react-native - 如何将原生 ios 第三方库集成到 React Native 应用程序中?
- python - 在包中使用动态文件
- jinja2 - saltstack jinja for 并行循环
- ruby-on-rails - 为什么我在 Ruby on Rails 中会出现这个 sqli3 错误?