From where CultureInfo.CurrentCulture reads culture

the MSDN says The culture is a property of the executing thread. This read-only property is equivalent to retrieving the CultureInfo object returned by the Thread.CurrentCulture property. When a thread is started, its culture is initially determined by calling the Windows GetUserDefaultLocaleName function. In other words, it’s based on the Thread, witch has a context… … Read more

How do I set CultureInfo.CurrentCulture from an App.Config file?

I don’t know a built-in way to set it from App.config, but you could just define a key in your App.config like this <configuration> <appSettings> <add key=”DefaultCulture” value=”pt-BR” /> </appSettings> </configuration> and in your application read that value and set the culture CultureInfo culture = new CultureInfo(ConfigurationManager.AppSettings[“DefaultCulture”]); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; Also, as … Read more

.NET (3.5) formats times using dots instead of colons as TimeSeparator for it-IT culture?

I can guarantee in Italy we use colons to separate hour and minute digits, and we use the 24-hour format. Wikipedia is correct (at least this time). Your problem is likely that you’re not setting the Thread’s UI culture. Something like this should work: Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(“it-IT”);

String format currency

I strongly suspect the problem is simply that the current culture of the thread handling the request isn’t set appropriately. You can either set it for the whole request, or specify the culture while formatting. Either way, I would suggest not use string.Format with a composite format unless you really have more than one thing … Read more

How to set decimal separators in ASP.NET MVC controllers?

I have just revisited the issue in a real project and finally found a working solution. Proper solution is to have a custom model binder for the type decimal (and decimal? if you’re using them): using System.Globalization; using System.Web.Mvc; public class DecimalModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { object result … Read more

Currency format for display

Try the Currency Format Specifier (“C”). It automatically takes the current UI culture into account and displays currency values accordingly. You can use it with either String.Format or the overloaded ToString method for a numeric type. For example: decimal value = 12345.6789M; // Be sure to use Decimal for money values. Do not use IEEE-754 … Read more