0

I am using c#.net3.5 and I want to change currentculture setting's decimal seperator from comma to dot, but at the same time I want user can use commas in numericupdown controlles as decimal seperator. So I tried to change my culture setting as below

CultureInfo newUIculture = new CultureInfo("tr-TR");
newUIculture.NumberFormat.CurrencyDecimalSeparator = ",";
newUIculture.NumberFormat.CurrencyGroupSeparator = ".";
newUIculture.NumberFormat.NumberDecimalSeparator = ",";
newUIculture.NumberFormat.NumberGroupSeparator = ".";
newUIculture.NumberFormat.PercentDecimalSeparator = ",";
newUIculture.NumberFormat.PercentGroupSeparator = ".";
//Application.CurrentUICulture = newUIculture;//this line giving error.
Thread.CurrentThread.CurrentUICulture = newUIculture;//this line doesn't work

CultureInfo newCulture = new CultureInfo("tr-TR");
newCulture.NumberFormat.CurrencyDecimalSeparator = ".";
newCulture.NumberFormat.CurrencyGroupSeparator = "";
newCulture.NumberFormat.NumberDecimalSeparator = ".";
newCulture.NumberFormat.NumberGroupSeparator = "";
newCulture.NumberFormat.PercentDecimalSeparator = ".";
newCulture.NumberFormat.PercentGroupSeparator = "";
Application.CurrentCulture = newCulture;//this one work fine

current culture settings work fine but currentUIculture setting doesn't work as I assigned parameters. how can I configure both settings with parameters I give?

Rapunzo
  • 966
  • 5
  • 21
  • 42

2 Answers2

0

CurrentUICulture is used to select which resource files are loaded. CurrentCulture determines the result of culture-dependent functions such as formatting dates and numbers. So the behavior you're seeing is expecte: you should be using CurrentCulture.

Joe
  • 122,218
  • 32
  • 205
  • 338
  • because of "UI" I thought maybe its connected with user interface.. I also think that I am doing something wrong. my aim is to change currentculture setting's decimal separator from comma to dot, but at the same time I want user can use commas in numericupdown controllers as decimal separator. is it possible with CurrentCulture? – Rapunzo Apr 22 '14 at 11:28
0

Peeking at System.Windows.Forms.Application.CurrentCulture, it's just a thin wrapper around Thread.CurrentThread.CurrentCulture, and there's no such thing as System.Windows.Forms.Application.CurrentUICulture, which would explain why your commented-out line is throwing errors for you.

If by "doesn't work", you mean "doesn't change the decimal separator like I want it to", then you've already answered your own question: CurrentCulture is the thing that controls that, not CurrentUICulture. There's a reason those are spelled differently.

Joe Amenta
  • 4,662
  • 2
  • 29
  • 38