在es-CL文化中,Windows Server 2012的货币十进制数字不正确 [英] Windows Server 2012 has incorrect decimal digits for currency on es-CL culture

查看:180
本文介绍了在es-CL文化中,Windows Server 2012的货币十进制数字不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows Server 2012似乎有几个与CultureInfo有关的问题。文化es-CL(即智利)中货币的十进制数字信息不正确,它表示2位数,但在智利我们不使用我们货币的小数。

Windows Server 2012 seems to have several issues regarding CultureInfo. The information about decimal digits for currencies in culture es-CL (that's Chile) is incorrect, it says 2 digits but here in Chile we don't use decimals in our currency.

有人知道补丁或者可能有办法覆盖这个设置吗?修改Windows Locale选项对我来说不起作用,因为我需要在MVC 5站点上工作。

Do anyone knows about a patch or maybe a way to override this setting? Modifying the Windows Locale options does not work for me, because I need this working on a MVC 5 site.

任何帮助,将不胜感激。

Any help, will be greatly appreciated.

PS:我的开发机器从未遇到过这个问题(我从Win7到10使用过),所以我猜这个问题只存在于Windows Server 2012上

PS: I never had this trouble with my dev-machine (I've use from Win7 to 10), so I'm guessing this issue only exists on Windows Server 2012

推荐答案

首先,让我告诉你这不是我需要的,但我会留在这里以防其他人需要补丁这个。

First of all, let me tell you this is not what I need, but I will leave it here in case someone else needs a patch for this.

另一种方法是修补源代码以覆盖货币中使用的小数位数(您可以覆盖所需的所有属性)。为此,您必须使用要覆盖的基础创建特定文化:

One alternative is to "patch" the source code in order to override the amount of decimal digits used in currencies (you can override all properties you want). To do this you have to Create a Specific Culture using as base the one you want to override:

culture = CultureInfo.CreateSpecificCulture("es-CL");
culture.NumberFormat.CurrencyDecimalDigits = 0;

然后将此culture变量分配给Current Thread:

And then assign this "culture" variable to the "Current Thread":

Thread.CurrentThread.CurrentCulture = culture;

最后,如果您像我一样使用MVC,您可以将此代码添加到ActionFilterAttribute中为了使所有调用都使用此设置:

Finally, if you are using MVC as me, you can add this code into an "ActionFilterAttribute" in order to make all calls use this settings:

public class LocalizationFilter : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        CultureInfo culture = CultureInfo.CreateSpecificCulture("es-CL");
        culture.NumberFormat.CurrencyDecimalDigits = 0;
        Thread.CurrentThread.CurrentCulture = culture;
    }
}

并且不要忘记注册您的过滤器,您的Global.asax包括以下行:

And don't forget to register your Filter, in your Global.asax include the following line:

GlobalFilters.Filters.Add(new LocalizationFilter());

这篇关于在es-CL文化中,Windows Server 2012的货币十进制数字不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆