Difference between CultureInfo.CreateSpecificCulture() and the constructor of the class?

The factory method has an fallback when it fails to create the culture info. So if you use a specific culture like ‘en-XX’, the culture info instance can’t be created, an exception will throw and a retry with the neutral culture ‘en’ will succeed. Below the source of the factory method public static CultureInfo CreateSpecificCulture(string … Read more

What is the “best” way to store international addresses in a database?

Plain freeform text. Validating all the world’s post/zip codes is too hard; a fixed list of countries is too politically sensitive; mandatory state/region/other administrative subdivision is just plain inappropriate (all too often I’m asked which county I live in–when I don’t, because Greater London is not a county at all). More to the point, it’s … 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

How to convert string to double with proper cultureinfo

You need to define a single locale that you will use for the data stored in the database, the invariant culture is there for exactly this purpose. When you display convert to the native type and then format for the user’s culture. E.g. to display: string fromDb = “123.56”; string display = double.Parse(fromDb, CultureInfo.InvariantCulture).ToString(userCulture); to … Read more

Converting country codes in .NET

The RegionInfo class does know the three-letter code (in the ThreeLetterISORegionName property), but I don’t think there is a way to get RegionInfo based on this code, you would need to enumerate all regions and add them to your own dictionary, with the three-letter code as a key. However, I think the .NET Framework uses … Read more

Detect decimal separator

Solution: private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { char a = Convert.ToChar(Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator); if (e.KeyChar == a) { e.Handled = true; textBox1.Text = “0”; } } That way, when you hit . or , you will have a 0 in your TextBox. EDIT: If you want to insert a 0 everytime you hit the decimal separator, … Read more

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 default culture info for entire c# application

Not for entire application or particular class. CurrentUICulture and CurrentCulture are settable per thread as discussed here Is there a way of setting culture for a whole application? All current threads and new threads?. You can’t change InvariantCulture at all. Sample code to change cultures for current thread: CultureInfo ci = new CultureInfo(theCultureString); Thread.CurrentThread.CurrentCulture = … Read more

MVC 3 jQuery Validation/globalizing of number/decimal field

You could try the jQuery Globalization plugin from Microsoft: <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/jquery.validate.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/jquery.validate.unobtrusive.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/jquery.glob.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/globinfo/jquery.glob.da-dk.js”)” type=”text/javascript”></script> <script type=”text/javascript”> $.validator.methods.number = function (value, element) { return !isNaN($.parseFloat(value)); } $(function () { $.preferCulture(‘da-DK’); }); </script> Plugin was renamed and moved, you should use Globalize (Mar 2012) <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/jquery.globalize/globalize.js”)” type=”text/javascript”></script> <script src=”https://stackoverflow.com/questions/5199835/@Url.Content(“~/Scripts/jquery.globalize/cultures/globalize.culture.da-DK.js”)” type=”text/javascript”></script> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)