如何更改.net Web应用程序中的默认文化设置?

时间:2022-11-05 22:45:53

Our web application (.net/C#) formats currency amounts using amount.ToString("c"), shown localized to a few different regions.

我们的Web应用程序(.net / C#)使用amount.ToString(“c”)格式化货币金额,显示为本地化到几个不同的区域。

Our French Candian users prefer all amounts to be the US format (123,456.99 vs. the default windows way for fr-CA of 123 456,99).

我们的法国Candian用户更喜欢所有金额为美国格式(123,456.99与默认的窗口方式为fr-CA为123 456,99)。

What is the best way to handle that ? Can I simply modify the regional settings on each webserver in windows for fr-ca? or do I need to create a custom culture?

处理这个问题的最佳方法是什么?我可以在Windows中为fr-ca简单地修改每个网络服务器上的区域设置吗?或者我是否需要创建自定义文化?

3 个解决方案

#1


You may want to look into creating a custom culture, providing the mix of formatting rules that you requre. There is an article at MSDN describing how to do it.

您可能希望研究创建自定义文化,提供您需要的混合格式规则。 MSDN上有一篇文章描述了如何做到这一点。

In short, you create a CultureAndRegionInfoBuilder object, define the name, set properties, and register it. Check the article for details.

简而言之,您创建CultureAndRegionInfoBuilder对象,定义名称,设置属性并注册它。查看文章了解详细信息。

#2


You can modify the current culture like so:

您可以像这样修改当前文化:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA")

You could pull the value from web.config, sure.

你可以从web.config中提取值,当然。

EDIT:

Ok, sorry I misunderstood.

好的,对不起我误会了。

This might work:

这可能有效:

  decimal d = 1232343456.99M;
  CultureInfo USFormat = new CultureInfo("en-US");      
  Console.Out.WriteLine(d.ToString(USFormat));

This should allow you to just use the USFormat when you're outputting numeric vals.

这应该允许您在输出数字值时使用USFormat。

#3


I would create a User Settings for the application, that would hold the CultureInfo for each user, and create a form to allow each user to edit the property ....

我将为应用程序创建一个用户设置,它将为每个用户保存CultureInfo,并创建一个表单以允许每个用户编辑属性....

#1


You may want to look into creating a custom culture, providing the mix of formatting rules that you requre. There is an article at MSDN describing how to do it.

您可能希望研究创建自定义文化,提供您需要的混合格式规则。 MSDN上有一篇文章描述了如何做到这一点。

In short, you create a CultureAndRegionInfoBuilder object, define the name, set properties, and register it. Check the article for details.

简而言之,您创建CultureAndRegionInfoBuilder对象,定义名称,设置属性并注册它。查看文章了解详细信息。

#2


You can modify the current culture like so:

您可以像这样修改当前文化:

Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-CA")

You could pull the value from web.config, sure.

你可以从web.config中提取值,当然。

EDIT:

Ok, sorry I misunderstood.

好的,对不起我误会了。

This might work:

这可能有效:

  decimal d = 1232343456.99M;
  CultureInfo USFormat = new CultureInfo("en-US");      
  Console.Out.WriteLine(d.ToString(USFormat));

This should allow you to just use the USFormat when you're outputting numeric vals.

这应该允许您在输出数字值时使用USFormat。

#3


I would create a User Settings for the application, that would hold the CultureInfo for each user, and create a form to allow each user to edit the property ....

我将为应用程序创建一个用户设置,它将为每个用户保存CultureInfo,并创建一个表单以允许每个用户编辑属性....