问题
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.
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: 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
回答1:
Gabriel check this configuration and try it.
https://i.stack.imgur.com/C0A4d.png
回答2:
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;
And then assign this "culture" variable to the "Current Thread":
Thread.CurrentThread.CurrentCulture = culture;
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;
}
}
And don't forget to register your Filter, in your Global.asax include the following line:
GlobalFilters.Filters.Add(new LocalizationFilter());
来源:https://stackoverflow.com/questions/44264980/windows-server-2012-has-incorrect-decimal-digits-for-currency-on-es-cl-culture